<?php

namespace App\Entity;

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

/**
 * @ORM\Entity(repositoryClass=HorairePassageRepository::class)
 * @ORM\Table(schema="sav")
 */
class HorairePassage
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(name="id",type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="time", nullable=true)
     */
    private $heure_debut;

    /**
     * @ORM\Column(type="time", nullable=true)
     */
    private $heure_fin;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $actif;

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

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

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

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

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

    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 getActif(): ?bool
    {
        return $this->actif;
    }

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

        return $this;
    }

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

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

        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->setHorairePassage($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->getHorairePassage() === $this) {
                $planning->setHorairePassage(null);
            }
        }

        return $this;
    }

    public function getLisibleHoraires() {
        $heure_debut = substr($this->heure_debut->format('Hi'), 0, 2) . 'h' . substr($this->heure_debut->format('Hi'), 2, 2);
        $heure_fin = substr($this->heure_fin->format('Hi'), 0, 2) . 'h' . substr($this->heure_fin->format('Hi'), 2, 2);

        return $heure_debut . ' - ' . $heure_fin;
    }

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

        return $this;
    }

}
