<?php

namespace App\Entity;

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

/**
 * @ORM\Entity(repositoryClass=TypePlanificationRepository::class)
 * @ORM\Table(schema="sav")
 */
class TypePlanification
{
    const ID_TYPE_VISITE_MES = 10;
    const ID_DETARTRAGE = 20;
    const ID_DETARTRAGE_HYC = 21;
    const ID_DET_BA_ECH = 36;
    const ID_DR_BA = 31;
    const ID_DR_CDC = 32;
    const ID_REMP_BA = 35;
    const ID_REMP_CDC = 33;
    const ID_BUREAU = 16;
    const ID_TECHNIQUE = 25;
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api", "site_list", "map", "planning"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=30)
     * @Groups({"api", "site_list", "planning"})
     */
    private $code;

    /**
     * @ORM\ManyToOne(targetEntity=CategoriePlanification::class, inversedBy="typePlanifications")
     * @ORM\JoinColumn(nullable=false, name="idcategorie_planification")
     */
    private $categorie_planification;

    /**
     * @ORM\Column(type="string", length=3)
     * @Groups({"site_list", "map", "planning"})
     */
    private $code_court;

    /**
     * @ORM\Column(type="string", length=50)
     * @Groups({"api", "site_list", "planning"})
     */
    private $libelle;

    /**
     * @ORM\Column(type="string", length=50)
     * @Groups({"site_list"})
     */
    private $libelle_fact;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     * @Groups({"site_list", "planning"})
     */
    private $nb_agent;

    /**
     * @ORM\ManyToOne(targetEntity=TypeDuree::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idtype_duree")
     * @Groups({"site_list", "planning"})
     */
    private $type_duree;

    /**
     * @ORM\Column(type="smallint", nullable=true)
     * @Groups({"site_list", "planning"})
     */
    private $duree;

    /**
     * @ORM\Column(type="string", length=50)
     * @Groups({"site_list", "map", "planning", "api"})
     */
    private $couleur;

    /**
     * @ORM\Column(type="boolean",  options={"default":true})
     * @Groups({"site_list"})
     */
    private $actif = true;

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

    /**
     * @ORM\OneToMany(targetEntity=Planning::class, mappedBy="type_planification_init")
     */
    private $plannings;

    /**
     * @ORM\OneToMany(targetEntity=EvenementLieuTypePlanification::class, mappedBy="type_planification")
     */
    private $evenementLieuTypePlanifications;

    /**
     * @ORM\OneToMany(targetEntity=EvenementObjet::class, mappedBy="type_planification")
     */
    private $evenementObjets;

    /**
     * @ORM\OneToMany(targetEntity=Evenement::class, mappedBy="type_planification")
     */
    private $evenements;

    /**
     * @ORM\OneToMany(targetEntity=AgentRestriction::class, mappedBy="type_planification")
     */
    private $agentRestrictions;

    /**
     * @ORM\OneToMany(targetEntity=TypePlanificationTypeAppareil::class, mappedBy="type_planification")
     */
    private $typePlanificationTypeAppareils;

    /**
     * @ORM\OneToMany(targetEntity=PlanningHistoriqueModification::class, mappedBy="type_planification")
     */
    private $planningHistoriqueModifications;

    public function __construct()
    {
        $this->interventions = new ArrayCollection();
        $this->plannings = new ArrayCollection();
        $this->evenementLieuTypePlanifications = new ArrayCollection();
        $this->evenementObjets = new ArrayCollection();
        $this->evenements = new ArrayCollection();
        $this->agentRestrictions = new ArrayCollection();
        $this->typePlanificationTypeAppareils = new ArrayCollection();
        $this->planningHistoriqueModifications = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }
    /**
     * @SerializedName("idtype_planification")
     * @Groups({"site_list"})
     */
    public function getIdTypePlanification(): ?int {
        return $this->getId();
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getCategoriePlanification(): ?CategoriePlanification
    {
        return $this->categorie_planification;
    }

    public function setCategoriePlanification(?CategoriePlanification $categorie_planification): self
    {
        $this->categorie_planification = $categorie_planification;

        return $this;
    }

    public function getCodeCourt(): ?string
    {
        return $this->code_court;
    }

    public function setCodeCourt(string $code_court): self
    {
        $this->code_court = $code_court;

        return $this;
    }

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

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

        return $this;
    }

    public function getLibelleFact(): ?string
    {
        return $this->libelle_fact;
    }

    public function setLibelleFact(string $libelle_fact): self
    {
        $this->libelle_fact = $libelle_fact;

        return $this;
    }

    public function getNbAgent(): ?int
    {
        return $this->nb_agent;
    }

    public function setNbAgent(int $nb_agent): self
    {
        $this->nb_agent = $nb_agent;

        return $this;
    }

    public function getTypeDuree(): ?TypeDuree
    {
        return $this->type_duree;
    }

    public function setTypeDuree(?TypeDuree $type_duree): self
    {
        $this->type_duree = $type_duree;

        return $this;
    }

    public function getDuree(): ?int
    {
        return $this->duree;
    }

    public function setDuree(int $duree): self
    {
        $this->duree = $duree;

        return $this;
    }

    public function getCouleur(): ?string
    {
        return $this->couleur;
    }

    public function setCouleur(string $couleur): self
    {
        $this->couleur = $couleur;

        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->setTypePlanification($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->getTypePlanification() === $this) {
                $intervention->setTypePlanification(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Planning>
     */
    public function getPlannings(): Collection
    {
        return $this->plannings;
    }

    public function addPlanning(Planning $planning): self
    {
        if (!$this->plannings->contains($planning)) {
            $this->plannings[] = $planning;
            $planning->setTypePlanificationInit($this);
        }

        return $this;
    }

    public function removePlanning(Planning $planning): self
    {
        if ($this->plannings->removeElement($planning)) {
            // set the owning side to null (unless already changed)
            if ($planning->getTypePlanificationInit() === $this) {
                $planning->setTypePlanificationInit(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, EvenementLieuTypePlanification>
     */
    public function getEvenementLieuTypePlanifications(): Collection
    {
        return $this->evenementLieuTypePlanifications;
    }

    public function addEvenementLieuTypePlanification(EvenementLieuTypePlanification $evenementLieuTypePlanification): self
    {
        if (!$this->evenementLieuTypePlanifications->contains($evenementLieuTypePlanification)) {
            $this->evenementLieuTypePlanifications[] = $evenementLieuTypePlanification;
            $evenementLieuTypePlanification->setTypePlanification($this);
        }

        return $this;
    }

    public function removeEvenementLieuTypePlanification(EvenementLieuTypePlanification $evenementLieuTypePlanification): self
    {
        if ($this->evenementLieuTypePlanifications->removeElement($evenementLieuTypePlanification)) {
            // set the owning side to null (unless already changed)
            if ($evenementLieuTypePlanification->getTypePlanification() === $this) {
                $evenementLieuTypePlanification->setTypePlanification(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, EvenementObjet>
     */
    public function getEvenementObjets(): Collection
    {
        return $this->evenementObjets;
    }

    public function addEvenementObjet(EvenementObjet $evenementObjet): self
    {
        if (!$this->evenementObjets->contains($evenementObjet)) {
            $this->evenementObjets[] = $evenementObjet;
            $evenementObjet->setTypePlanification($this);
        }

        return $this;
    }

    public function removeEvenementObjet(EvenementObjet $evenementObjet): self
    {
        if ($this->evenementObjets->removeElement($evenementObjet)) {
            // set the owning side to null (unless already changed)
            if ($evenementObjet->getTypePlanification() === $this) {
                $evenementObjet->setTypePlanification(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Evenement>
     */
    public function getEvenements(): Collection
    {
        return $this->evenements;
    }

    public function addEvenement(Evenement $evenement): self
    {
        if (!$this->evenements->contains($evenement)) {
            $this->evenements[] = $evenement;
            $evenement->setTypePlanification($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->getTypePlanification() === $this) {
                $evenement->setTypePlanification(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, AgentRestriction>
     */
    public function getAgentRestrictions(): Collection
    {
        return $this->agentRestrictions;
    }

    public function addAgentRestriction(AgentRestriction $agentRestriction): self
    {
        if (!$this->agentRestrictions->contains($agentRestriction)) {
            $this->agentRestrictions[] = $agentRestriction;
            $agentRestriction->setTypePlanification($this);
        }

        return $this;
    }

    public function removeAgentRestriction(AgentRestriction $agentRestriction): self
    {
        if ($this->agentRestrictions->removeElement($agentRestriction)) {
            // set the owning side to null (unless already changed)
            if ($agentRestriction->getTypePlanification() === $this) {
                $agentRestriction->setTypePlanification(null);
            }
        }

        return $this;
    }

    /** @SerializedName("categorie_planif_name")
     * @Groups({"site_list"})
     */
    public function getCategoriePlanificationName() {
        return $this->getCategoriePlanification()->getLibelle();
    }

    public function getActif(): ?bool
    {
        return $this->actif;
    }

    public function setActif(?bool $actif): self
    {
        $this->actif = $actif;

        return $this;
    }

    /** @SerializedName("type_appareil_IDs")
     * @Groups({"site_list"})
     */
    public function getTypeAppareilIDs() {
        $resultat= [];
        foreach ($this->getTypePlanificationTypeAppareils() as $typePlanificationTypeAppareil) {
            $resultat[] = $typePlanificationTypeAppareil->getTypeAppareil()->getId();
        }
        return $resultat;
    }

/**
 * @return Collection<int, TypePlanificationTypeAppareil>
 */
public function getTypePlanificationTypeAppareils(): Collection
{
    return $this->typePlanificationTypeAppareils;
}

public function addTypePlanificationTypeAppareil(TypePlanificationTypeAppareil $typePlanificationTypeAppareil): self
{
    if (!$this->typePlanificationTypeAppareils->contains($typePlanificationTypeAppareil)) {
        $this->typePlanificationTypeAppareils[] = $typePlanificationTypeAppareil;
        $typePlanificationTypeAppareil->setTypePlanification($this);
    }

    return $this;
}

public function removeTypePlanificationTypeAppareil(TypePlanificationTypeAppareil $typePlanificationTypeAppareil): self
{
    if ($this->typePlanificationTypeAppareils->removeElement($typePlanificationTypeAppareil)) {
        // set the owning side to null (unless already changed)
        if ($typePlanificationTypeAppareil->getTypePlanification() === $this) {
            $typePlanificationTypeAppareil->setTypePlanification(null);
        }
    }

    return $this;
}

    public function isSurValidation() {
        return in_array($this->id,
            [
                self::ID_DETARTRAGE,
                self::ID_DETARTRAGE_HYC,
                self::ID_DET_BA_ECH,
                self::ID_DR_BA,
                self::ID_DR_CDC,
                self::ID_REMP_BA,
                self::ID_REMP_CDC,
                self::ID_BUREAU,
                self::ID_TECHNIQUE
            ]);
    }

    /**
     * @return Collection<int, PlanningHistoriqueModification>
     */
    public function getPlanningHistoriqueModifications(): Collection
    {
        return $this->planningHistoriqueModifications;
    }

    public function addPlanningHistoriqueModification(PlanningHistoriqueModification $planningHistoriqueModification): self
    {
        if (!$this->planningHistoriqueModifications->contains($planningHistoriqueModification)) {
            $this->planningHistoriqueModifications[] = $planningHistoriqueModification;
            $planningHistoriqueModification->setTypePlanification($this);
        }

        return $this;
    }

    public function removePlanningHistoriqueModification(PlanningHistoriqueModification $planningHistoriqueModification): self
    {
        if ($this->planningHistoriqueModifications->removeElement($planningHistoriqueModification)) {
            // set the owning side to null (unless already changed)
            if ($planningHistoriqueModification->getTypePlanification() === $this) {
                $planningHistoriqueModification->setTypePlanification(null);
            }
        }

        return $this;
    }
}
