<?php

namespace App\Entity;

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

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

    /**
     * @ORM\ManyToOne(targetEntity=TypePlanification::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idtype_planification_init")
     * @Groups({"map", "planning", "api"})
     */
    private $type_planification_init;

    /**
     * @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idutilisateur_agent")
     * @Groups({"map", "planning", "api"})
     */
    private $utilisateur_agent;

    /**
     * @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idutilisateur_planning")
     */
    private $utilisateur_planning;

    /**
     * @ORM\ManyToOne(targetEntity=Equipement::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idequipement")
     * @Groups({"planning", "api"})
     */
    private $equipement;

    /**
     * @ORM\Column(type="date")
     */
    private $date_creation;

    /**
     * @ORM\Column(type="date")
     * @Groups({"map", "planning", "api"})
     */
    private $date;

    /**
     * @ORM\Column(type="smallint")
     * @Groups({"map", "planning", "api"})
     */
    private $statut;

    /**
     * @ORM\Column(type="time", nullable=true)
     * @Groups({"map", "planning", "api"})
     */
    private $heure_debut;

    /**
     * @ORM\Column(type="time", nullable=true)
     * @Groups({"map", "planning", "api"})
     */
    private $heure_fin;

    /**
     * @ORM\Column(type="smallint")
     * @Groups({"planning", "api"})
     */
    private $rang_tri;

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

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

    /**
     * @ORM\ManyToOne(targetEntity=MomentPassage::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idmoment_passage")
     * @Groups({"map", "planning", "api"})
     */
    private $moment_passage;

    /**
     * @ORM\ManyToOne(targetEntity=HorairePassage::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idhoraire_passage")
     * @Groups({"map", "planning", "api"})
     */
    private $horaire_passage;

    /**
     * @ORM\Column(type="boolean")
     * @Groups({"planning", "api"})
     */
    private $horaire_specifie;

    /**
     * @ORM\Column(type="time", nullable=true)
     * @Groups({"planning", "api"})
     */
    private $heure_debut_specifiee;

    /**
     * @ORM\Column(type="time", nullable=true)
     * @Groups({"planning", "api"})
     */
    private $heure_fin_specifiee;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"planning", "api"})
     */
    private $code_regroup;

    /**
     * @ORM\ManyToOne(targetEntity=Site::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idsite")
     */
    private $site;

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

    /**
     * @ORM\ManyToOne(targetEntity=PlanningInitiativeType::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idplanning_initiative_type")
     * @Groups({"planning"})
     */
    private $planning_initiative_type;

    /**
     * @ORM\ManyToOne(targetEntity=PlanningInitiativeDetail::class, inversedBy="plannings")
     * @ORM\JoinColumn(nullable=false, name="idplanning_initiative_detail")
     * @Groups({"planning"})
     */
    private $planning_initiative_detail;

    /**
     * @ORM\OneToOne(targetEntity=Intervention::class, mappedBy="planning")
     * @Groups({"api"})
     */
    private $intervention;

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

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

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

    public function getTypePlanificationInit(): ?TypePlanification
    {
        return $this->type_planification_init;
    }

    public function setTypePlanificationInit(?TypePlanification $type_planification_init): self
    {
        $this->type_planification_init = $type_planification_init;

        return $this;
    }

    public function getUtilisateurAgent(): ?Utilisateur
    {
        return $this->utilisateur_agent;
    }

    public function setUtilisateurAgent(?Utilisateur $utilisateur_agent): self
    {
        $this->utilisateur_agent = $utilisateur_agent;

        return $this;
    }

    public function getUtilisateurPlanning(): ?Utilisateur
    {
        return $this->utilisateur_planning;
    }

    public function setUtilisateurPlanning(?Utilisateur $utilisateur_planning): self
    {
        $this->utilisateur_planning = $utilisateur_planning;

        return $this;
    }

    public function getEquipement(): ?Equipement
    {
        return $this->equipement;
    }

    public function setEquipement(?Equipement $equipement): self
    {
        $this->equipement = $equipement;

        return $this;
    }

    public function getDateCreation(): ?\DateTimeInterface
    {
        return $this->date_creation;
    }

    public function setDateCreation(\DateTimeInterface $date_creation): self
    {
        $this->date_creation = $date_creation;

        return $this;
    }

    public function getDate(): ?\DateTimeInterface
    {
        return $this->date;
    }

    public function setDate(\DateTimeInterface $date): self
    {
        $this->date = $date;

        return $this;
    }

    public function getStatut(): ?int
    {
        return $this->statut;
    }

    public function setStatut(int $statut): self
    {
        $this->statut = $statut;

        return $this;
    }

    public function getHeureDebut(): ?\DateTimeInterface
    {
        return $this->heure_debut;
    }

    public function setHeureDebut(?\DateTimeInterface $heure_debut): self
    {
        $this->heure_debut = $heure_debut;

        return $this;
    }

    public function getHeureFin(): ?\DateTimeInterface
    {
        return $this->heure_fin;
    }

    public function setHeureFin(?\DateTimeInterface $heure_fin): self
    {
        $this->heure_fin = $heure_fin;

        return $this;
    }

    public function getRangTri(): ?int
    {
        return $this->rang_tri;
    }

    public function setRangTri(int $rang_tri): self
    {
        $this->rang_tri = $rang_tri;

        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 getMomentPassage(): ?MomentPassage
    {
        return $this->moment_passage;
    }

    public function setMomentPassage(?MomentPassage $moment_passage): self
    {
        $this->moment_passage = $moment_passage;

        return $this;
    }

    public function getHorairePassage(): ?HorairePassage
    {
        return $this->horaire_passage;
    }

    public function setHorairePassage(?MomentPassage $horaire_passage): self
    {
        $this->horaire_passage = $horaire_passage;

        return $this;
    }

    public function getHoraireSpecifie(): ?bool
    {
        return $this->horaire_specifie;
    }

    public function setHoraireSpecifie(bool $horaire_specifie): self
    {
        $this->horaire_specifie = $horaire_specifie;

        return $this;
    }

    public function getHeureDebutSpecifiee(): ?\DateTimeInterface
    {
        return $this->heure_debut_specifiee;
    }

    public function setHeureDebutSpecifiee(?\DateTimeInterface $heure_debut_specifiee): self
    {
        $this->heure_debut_specifiee = $heure_debut_specifiee;

        return $this;
    }

    public function getHeureFinSpecifiee(): ?\DateTimeInterface
    {
        return $this->heure_fin_specifiee;
    }

    public function setHeureFinSpecifiee(?\DateTimeInterface $heure_fin_specifiee): self
    {
        $this->heure_fin_specifiee = $heure_fin_specifiee;

        return $this;
    }

    public function getCodeRegroup(): ?int
    {
        return $this->code_regroup;
    }

    public function setCodeRegroup(?int $code_regroup): self
    {
        $this->code_regroup = $code_regroup;

        return $this;
    }

    public function getSite(): ?Site
    {
        return $this->site;
    }

    public function setSite(?Site $site): self
    {
        $this->site = $site;

        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->setPlanning($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->getPlanning() === $this) {
                $evenement->setPlanning(null);
            }
        }

        return $this;
    }

    /**
     * @SerializedName("libelleStatut")
     * @Groups({"map"})
     */
    public function getLibelleStatut(): ?string
    {
        switch ($this->statut) {
            case '0':
                $libelleStatut = 'Intervention créée';
                break;
            case '1':
                $libelleStatut = 'Intervention reçue';
                break;
            case '2':
                $libelleStatut = 'Intervention débutée';
                break;
            case '3':
                $libelleStatut = 'Intervention terminée';
                break;
            case '4':
                $libelleStatut = 'Intervention annulée';
                break;
            default:
                $libelleStatut = 'Intervention non reconnue';
        }
        return $libelleStatut;
    }

    public function getPlanningInitiativeType(): ?PlanningInitiativeType
    {
        return $this->planning_initiative_type;
    }

    public function setPlanningInitiativeType(?PlanningInitiativeType $planning_initiative_type): self
    {
        $this->planning_initiative_type = $planning_initiative_type;

        return $this;
    }

    public function getPlanningInitiativeDetail(): ?PlanningInitiativeDetail
    {
        return $this->planning_initiative_detail;
    }

    public function setPlanningInitiativeDetail(?PlanningInitiativeDetail $planning_initiative_detail): self
    {
        $this->planning_initiative_detail = $planning_initiative_detail;

        return $this;
    }

    public function getIntervention(): ?Intervention
    {
        return $this->intervention;
    }

    public function setIntervention(?Intervention $intervention): self
    {
        $this->intervention = $intervention;

        return $this;
    }

    /**
     * @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->setPlanning($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->getPlanning() === $this) {
                $planningHistoriqueModification->setPlanning(null);
            }
        }

        return $this;
    }

    public function getLastPlanningHistoriqueModification(): ?PlanningHistoriqueModification
    {
        return ($last = $this->planningHistoriqueModifications->last()) ?  $last : null;
    }
}
