<?php

namespace App\Entity;

use App\Repository\RetourRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ORM\Entity(repositoryClass=RetourRepository::class)
 * @ORM\Table(schema="sav")
 */
class Retour
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=40, nullable=true)
     * @Groups({"api"})
     */
    private $libelle;

    /**
     * @ORM\ManyToOne(targetEntity=TypeRetour::class, inversedBy="retours")
     * @ORM\JoinColumn(name="idtype_retour")
     */
    private $type_retour;

    /**
     * @ORM\OneToMany(targetEntity=Intervention::class, mappedBy="retour")
     */
    private $interventions;

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

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

    public function getLibelle(): ?string
    {
        return $this->libelle;
    }

    public function setLibelle(?string $libelle): self
    {
        $this->libelle = $libelle;

        return $this;
    }

    public function getTypeRetour(): ?TypeRetour
    {
        return $this->type_retour;
    }

    public function setTypeRetour(?TypeRetour $type_retour): self
    {
        $this->type_retour = $type_retour;

        return $this;
    }

    /**
     * @return Collection<int, Intervention>
     */
    public function getInterventions(): Collection
    {
        return $this->interventions;
    }

    public function addIntervention(Intervention $intervention): self
    {
        if (!$this->interventions->contains($intervention)) {
            $this->interventions[] = $intervention;
            $intervention->setRetour($this);
        }

        return $this;
    }

    public function removeIntervention(Intervention $intervention): self
    {
        if ($this->interventions->removeElement($intervention)) {
            // set the owning side to null (unless already changed)
            if ($intervention->getRetour() === $this) {
                $intervention->setRetour(null);
            }
        }

        return $this;
    }

}
