<?php

namespace App\Entity;

use App\Repository\AnimalRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;

/**
 * @ORM\Entity(repositoryClass=AnimalRepository::class)
 * @ORM\Table(name="`animal`")
 * @ApiResource(
 * normalizationContext={"groups"={"read:Animal"}},
 * denormalizationContext={"groups"={"write:Animal"}}
 * )
 */
class Animal
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"read:Animal","read:User"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $nom;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $datenaissance;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $pere;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $mere;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $poids;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $marquage;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $race;

    /**
     * @ORM\OneToMany(targetEntity=Evenement::class, mappedBy="animal")
     * @Groups({"read:Animal","read:User"})
     */
    private $evenements;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $sexe;

    /**
     * @ORM\ManyToOne(targetEntity=User::class, inversedBy="animals")
     * @Groups({"read:Animal","write:Animal","read:User"})
     */
    private $user;

    public function __construct()
    {
        $this->evenements = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getNom(): ?string
    {
        return $this->nom;
    }

    public function setNom(?string $nom): self
    {
        $this->nom = $nom;

        return $this;
    }

    public function getDatenaissance(): ?string
    {
        return $this->datenaissance;
    }

    public function setDatenaissance(?string $datenaissance): self
    {
        $this->datenaissance = $datenaissance;

        return $this;
    }

    public function getPere(): ?string
    {
        return $this->pere;
    }

    public function setPere(?string $pere): self
    {
        $this->pere = $pere;

        return $this;
    }

    public function getMere(): ?string
    {
        return $this->mere;
    }

    public function setMere(?string $mere): self
    {
        $this->mere = $mere;

        return $this;
    }

    public function getPoids(): ?string
    {
        return $this->poids;
    }

    public function setPoids(?string $poids): self
    {
        $this->poids = $poids;

        return $this;
    }

    public function getMarquage(): ?string
    {
        return $this->marquage;
    }

    public function setMarquage(?string $marquage): self
    {
        $this->marquage = $marquage;

        return $this;
    }

    public function getRace(): ?string
    {
        return $this->race;
    }

    public function setRace(?string $race): self
    {
        $this->race = $race;

        return $this;
    }

    /**
     * @return Collection|Evenement[]
     */
    public function getEvenements(): Collection
    {
        return $this->evenements;
    }

    public function addEvenement(Evenement $evenement): self
    {
        if (!$this->evenements->contains($evenement)) {
            $this->evenements[] = $evenement;
            $evenement->setAnimal($this);
        }

        return $this;
    }

    public function removeEvenement(Evenement $evenement): self
    {
        if ($this->evenements->removeElement($evenement)) {
            // set the owning side to null (unless already changed)
            if ($evenement->getAnimal() === $this) {
                $evenement->setAnimal(null);
            }
        }

        return $this;
    }

    public function getSexe(): ?string
    {
        return $this->sexe;
    }

    public function setSexe(?string $sexe): self
    {
        $this->sexe = $sexe;

        return $this;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }
}
