<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\PitchRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PitchRepository::class)]
#[UniqueEntity(fields:'label', message:'Le nom existe déjà')]
#[ApiFilter(SearchFilter::class, properties: ['location.label' => 'ipartial','label' => 'ipartial','typePitch'=>'exact'])]
#[ApiFilter(BooleanFilter::class, properties: ['isActived'])]
#[ApiFilter(OrderFilter::class, properties: ['note' => 'DESC'])]
#[ApiResource(
normalizationContext: ['groups' => ['pitch:read']],
denormalizationContext:[
'groups'=>['pitch:write']
],
order: ["id" => "DESC"]
)]
class Pitch
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['pitch:read','reservation:read','favoris:read','abonnement:read'])]
private $id;
#[ORM\Column(type: 'string', length: 45)]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Groups(['pitch:read','pitch:write','reservation:read','favoris:read','abonnement:read'])]
private $label;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\Type(type:"integer")]
#[Assert\Positive]
private $note;
#[ORM\Column(type: 'boolean', nullable: true)]
#[Assert\Type(type:"bool")]
private $isDisponible;
#[ORM\ManyToOne(targetEntity: Location::class, inversedBy: 'pitches')]
#[Assert\NotBlank]
#[Assert\NotNull]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['pitch:read','pitch:write','reservation:read','favoris:read'])]
private $location;
#[ORM\OneToMany(mappedBy: 'pitch', targetEntity: Album::class)]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Groups(['pitch:read','pitch:write','favoris:read','reservation:read'])]
private $albums;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['pitch:read','pitch:write','favoris:read'])]
private $description;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $indicator;
#[ORM\OneToMany(mappedBy: 'pitch', targetEntity: Reservation::class)]
private $reservations;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isActived;
#[ORM\OneToMany(mappedBy: 'pitch', targetEntity: Abonnement::class)]
private $abonnements;
#[ORM\OneToMany(mappedBy: 'pitch', targetEntity: Academy::class)]
private $academies;
#[Groups(['pitch:read','pitch:write','favoris:read','reservation:read'])]
#[ORM\ManyToOne(targetEntity: TypePitch::class, inversedBy: 'pitches')]
private $typePitch;
public function __construct()
{
$this->albums = new ArrayCollection();
$this->reservations = new ArrayCollection();
$this->abonnements = new ArrayCollection();
$this->academies = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getNote(): ?int
{
return $this->note;
}
public function setNote(int $note): self
{
$this->note = $note;
return $this;
}
public function isIsDisponible(): ?bool
{
return $this->isDisponible;
}
public function setIsDisponible(bool $isDisponible): self
{
$this->isDisponible = $isDisponible;
return $this;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function setLocation(?Location $location): self
{
$this->location = $location;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(?int $price): self
{
$this->price = $price;
return $this;
}
/**
* @return Collection<int, Album>
*/
public function getAlbums(): Collection
{
return $this->albums;
}
public function addAlbum(Album $album): self
{
if (!$this->albums->contains($album)) {
$this->albums[] = $album;
$album->setPitch($this);
}
return $this;
}
public function removeAlbum(Album $album): self
{
if ($this->albums->removeElement($album)) {
// set the owning side to null (unless already changed)
if ($album->getPitch() === $this) {
$album->setPitch(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getIndicator(): ?string
{
return $this->indicator;
}
public function setIndicator(string $indicator): self
{
$this->indicator = $indicator;
return $this;
}
/**
* @return Collection<int, Reservation>
*/
public function getReservations(): Collection
{
return $this->reservations;
}
public function addReservation(Reservation $reservation): self
{
if (!$this->reservations->contains($reservation)) {
$this->reservations[] = $reservation;
$reservation->setPitch($this);
}
return $this;
}
public function removeReservation(Reservation $reservation): self
{
if ($this->reservations->removeElement($reservation)) {
// set the owning side to null (unless already changed)
if ($reservation->getPitch() === $this) {
$reservation->setPitch(null);
}
}
return $this;
}
public function isIsActived(): ?bool
{
return $this->isActived;
}
public function setIsActived(?bool $isActived): self
{
$this->isActived = $isActived;
return $this;
}
/**
* @return Collection<int, Abonnement>
*/
public function getAbonnements(): Collection
{
return $this->abonnements;
}
/**
* @return Collection<int, Academy>
*/
public function getAcademies(): Collection
{
return $this->academies;
}
public function addAcademy(Academy $academy): self
{
if (!$this->academies->contains($academy)) {
$this->academies[] = $academy;
$academy->setPitch($this);
}
return $this;
}
public function removeAcademy(Academy $academy): self
{
if ($this->academies->removeElement($academy)) {
// set the owning side to null (unless already changed)
if ($academy->getPitch() === $this) {
$academy->setPitch(null);
}
}
return $this;
}
public function getTypePitch(): ?TypePitch
{
return $this->typePitch;
}
public function setTypePitch(?TypePitch $typePitch): self
{
$this->typePitch = $typePitch;
return $this;
}
}