<?php

namespace App\Entity;

use App\Repository\InterventionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use App\Doctrine\DBAL\Types\ReparationEnumType;

/**
 * @ORM\Entity(repositoryClass=InterventionRepository::class)
 * @ORM\Table(schema="sav")
 */
class Intervention
{
    /*dans oracle
    const RDV_WAITING = 0;
    const RDV_SENT    = 1;
    const RDV_START   = 3;
    const RDV_ENDED   = 2;
    const RDV_ABS     = 4;
    const RDV_ABANDON = 7;
    */

    //statut planning
    const CREATED     = 0;
    const RECEIVED    = 1;
    const STARTED     = 2;
    const FINISHED    = 3;
    const CANCELED    = 4;

    //statut champs
    const STATUS_CREATE = 1;
    const STATUS_UPDATE = 2;
    const STATUS_DELETE = 3;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api", "map"})
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity=Devis::class, mappedBy="intervention")
     * @Ignore()
     */
    private $devis;

    /**
     * @ORM\OneToMany(targetEntity=Facture::class, mappedBy="intervention")
     * @Ignore()
     */
    private $factures;

    /**
     * @ORM\OneToMany(targetEntity=Privilege::class, mappedBy="intervention")
     * @Ignore()
     */
    private $privileges;

    /**
     * @ORM\OneToOne(targetEntity=Planning::class, inversedBy="intervention")
     * @ORM\JoinColumn(name="idplanning", referencedColumnName="id")
     * @Groups({"map"})
     */
    private $planning;

    /**
     * @ORM\ManyToOne(targetEntity=Equipement::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idequipement")
     * @Groups({"map"})
     */
    private $equipement;

    /**
     * @ORM\ManyToOne(targetEntity=Client::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idclient_payeur_tiers")
     * @Groups({"api"})
     */
    private $client_payeur_tiers;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $avis_passage;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $avis_passage_mail;

    /**
     * @ORM\Column(type="string", length=200, nullable=true)
     * @Groups({"api", "map"})
     */
    private $memo;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"map"})
     */
    private $temps;

    /**
     * @ORM\ManyToOne(targetEntity=InterventionMotif::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idintervention_motif")
     */
    private $intervention_motif;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $horaire_a_controler;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"api"})
     */
    private $mesure_co;

    /**
     * @ORM\Column(type="text", nullable=true)
     * @Groups({"api"})
     */
    private $observations;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $cgv_acceptees;

    /**
     * @ORM\Column(type="text", nullable=true)
     * @Groups({"api"})
     */
    private $commentaire_client;

    /**
     * @ORM\ManyToOne(targetEntity=TypeEnvoi::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idtype_envoi_rapport")
     * @Groups({"api"})
     */
    private $type_envoi_rapport;

    /**
     * @ORM\Column(type="string", length=200, nullable=true)
     * @Groups({"api"})
     */
    private $motif_modif_code_int;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $cli_refus_signature;

    /**
     * @ORM\Column(type="string", length=200, nullable=true)
     * @Groups({"api"})
     */
    private $commentaire_refus_signature;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"api"})
     */
    private $fiche_papier_liee;

    /**
     * @ORM\ManyToOne(targetEntity=ContratTarif::class, inversedBy="interventions", cascade={"persist"})
     * @ORM\JoinColumn(name="idcontrat_tarif")
     * @Groups({"api"})
     */
    private $contrat_tarif;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $encaissement_effectue;

    /**
     * @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idutilisateur_validation_technique")
     */
    private $utilisateur_validation_technique;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $date_validation_technique;

    /**
     * @ORM\ManyToOne(targetEntity=InterventionTypeValidation::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idtype_validation_technique")
     */
    private $type_validation_technique;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $commentaire_technique;

    /**
     * @ORM\ManyToOne(targetEntity=Utilisateur::class)
     * @ORM\JoinColumn(name="idutilisateur_validation_adm")
     */
    private $utilisateur_validation_adm;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $date_validation_adm;

    /**
     * @ORM\ManyToOne(targetEntity=InterventionTypeValidation::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idtype_validation_adm")
     */
    private $type_validation_adm;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $entretien;

    /**
     * @ORM\ManyToOne(targetEntity=Site::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idsite")
     */
    private $site;

    /**
     * @ORM\ManyToOne(targetEntity=TypeVisiteIntervention::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idtype_visite_intervention")
     * @Groups({"api"})
     */
    private $type_visite_intervention;

    /**
     * @ORM\OneToMany(targetEntity=ContratResiliation::class, mappedBy="intervention")
     * @Ignore()
     */
    private $contratResiliations;

    /**
     * @ORM\OneToMany(targetEntity=EquipementMesure::class, mappedBy="intervention", orphanRemoval=true)
     * @Ignore()
     */
    private $equipementMesures;

    /**
     * @SerializedName("equipementMesure")
     * @Groups({"api"})
     */
    public function getEquipementMesure() {

        return ($this->getEquipementMesures()->count() > 0) ? $this->getEquipementMesures()->first() : null;
    }

    /**
     * @ORM\OneToMany(targetEntity=InterventionMedia::class, mappedBy="intervention", orphanRemoval=true, cascade={"persist"})
     * @Groups({"api"})
     */
    private $interventionMedias;

    /**
     * @Groups({"api"})
     */
    private $interventionClasseEnergetique;

    /**
     * @ORM\Column(type="binary", nullable=true)
     */
    private $stack;

    /**
     * @Groups({"api"})
     */
    private $forfaits;

    /**
     * @Groups({"api"})
     */
    private $deplacement;

    /**
     * @Groups({"api"})
     */
    private $produits;

    /**
     * @Groups({"api"})
     */
    private $piecesHistorique;

    /**
     * @Groups({"api"})
     */
    private $anomalieHistorique;

    /**
     * @Groups({"api"})
     */
    private $contratTarifs;

    /**
     * @ORM\ManyToOne(targetEntity=AttestationEntretien::class, inversedBy="interventions", cascade={"persist"})
     * @ORM\JoinColumn(name="idattestation_entretien")
     * @Groups({"api"})
     */
    private $attestation_entretien;

    /**
     * @Groups({"api"})
     */
    private $zud;

    /**
     * @Groups({"api"})
     */
    private $moyenPaiement;

    /**
     * @ORM\ManyToOne(targetEntity=Retour::class, inversedBy="interventions", cascade={"persist"})
     * @ORM\JoinColumn(name="idretour")
     * @Groups({"api"})
     */
    private $retour;

    /**
     * @ORM\OneToMany(targetEntity=InterventionAnomalie::class, mappedBy="intervention")
     * @Groups({"api"})
     */
    private $interventionAnomalies;

    /**
     * @ORM\Column(type="string", length=50, nullable=true)
     * @Groups({"api"})
     */
    private $marque_appareil;

    /**
     * @ORM\Column(type="string", length=50, nullable=true)
     * @Groups({"api"})
     */
    private $modele_appareil;

    /**
     * @ORM\Column(type="string", length=150, nullable=true)
     * @Groups({"api"})
     */
    private $email_envoi_rapport;

    /**
     * @ORM\Column(type="date", nullable=true)
     * @Groups({"api"})
     */
    private $date_dernier_controle_etancheite;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $fuite;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"api"})
     */
    private $fuite_nb;

    /**
     * @ORM\Column(type="reparation", nullable=true)
     * @Groups({"api"})
     */
    private $reparation;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $cerfa;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     * @Groups({"api"})
     */
    private $envoi_facture;

    /**
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"api"})
     */
    private $numfiche_oracle;

    /**
     * @ORM\OneToMany(targetEntity=InterventionAnnulation::class, mappedBy="intervention")
     */
    private $interventionAnnulations;

    /**
     * @ORM\ManyToOne(targetEntity=TypePlanification::class, inversedBy="interventions")
     * @ORM\JoinColumn(name="idtype_planification")
     * @Groups({"api"})

     */
    private $type_planification;

    /**
     * @ORM\OneToMany(targetEntity=InterventionMesure::class, mappedBy="intervention")
     */
    private $interventionMesures;

    /**
     * @ORM\OneToMany(targetEntity=InterventionDocument::class, mappedBy="intervention")
     */
    private $interventionDocuments;

    /**
     * @ORM\OneToMany(targetEntity=EquipementHauteur::class, mappedBy="intervention")
     */
    private $equipementHauteurs;

    /**
     * @ORM\OneToMany(targetEntity=HistoriqueEquipementLocal::class, mappedBy="intervention")
     */
    private $historiqueEquipementLocals;

    /**
     * @ORM\Column(type="string", length=200)
     */
    private $num_bon_commande;

    public static function update(Intervention $intervOrigine, Intervention $intervModif, TypeEnvoi $typeEnvoiRapport, TypePlanification $typePlanificationInit = null, TypeVisiteIntervention $typeVisiteIntervention = null, $stack) {

        $intervOrigine
            ->setMemo($intervModif->getMemo())
            ->setMesureCo($intervModif->getMesureCo())
            ->setObservations($intervModif->getObservations())
            ->setCgvAcceptees($intervModif->getCgvAcceptees())
            ->setCommentaireClient($intervModif->getCommentaireClient())
            ->setTypeEnvoiRapport($typeEnvoiRapport)
            ->setMotifModifCodeInt($intervModif->getMotifModifCodeInt())
            ->setCliRefusSignature($intervModif->getCliRefusSignature())
            ->setCommentaireRefusSignature($intervModif->getCommentaireRefusSignature())
            ->setFichePapierLiee($intervModif->getFichePapierLiee())
            ->setTypePlanificationInit($typePlanificationInit)
            ->setEntretien($intervModif->getEntretien())
            ->setTypeVisiteIntervention($typeVisiteIntervention)
            ->setStack($stack)
        ;
        return $intervOrigine;
    }

    public function __construct()
    {
        $this->devis = new ArrayCollection();
        $this->factures = new ArrayCollection();
        $this->privileges = new ArrayCollection();
        $this->contratResiliations = new ArrayCollection();
        $this->equipementMesures = new ArrayCollection();
        $this->interventionMedias = new ArrayCollection();
        $this->interventionAnomalies = new ArrayCollection();
        $this->interventionAnnulations = new ArrayCollection();
        $this->interventionMesures = new ArrayCollection();
        $this->interventionDocuments = new ArrayCollection();
        $this->equipementHauteurs = new ArrayCollection();
        $this->historiqueEquipementLocals = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function setId(?int $id): self
    {
        $this->id = $id;

        return $this;
    }

    /**
     * @return Collection<int, Devis>
     */
    public function getDevis(): Collection
    {
        return $this->devis;
    }

    public function addDevis(Devis $devi): self
    {
        if (!$this->devis->contains($devi)) {
            $this->devis[] = $devi;
            $devi->setIntervention($this);
        }

        return $this;
    }

    public function removeDevis(Devis $devi): self
    {
        if ($this->devis->removeElement($devi)) {
            // set the owning side to null (unless already changed)
            if ($devi->getIntervention() === $this) {
                $devi->setIntervention(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Facture>
     */
    public function getFactures(): Collection
    {
        return $this->factures;
    }

    public function addFacture(Facture $facture): self
    {
        if (!$this->factures->contains($facture)) {
            $this->factures[] = $facture;
            $facture->setIntervention($this);
        }

        return $this;
    }

    public function removeFacture(Facture $facture): self
    {
        if ($this->factures->removeElement($facture)) {
            // set the owning side to null (unless already changed)
            if ($facture->getIntervention() === $this) {
                $facture->setIntervention(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Privilege>
     */
    public function getPrivileges(): Collection
    {
        return $this->privileges;
    }

    public function addPrivilege(Privilege $privilege): self
    {
        if (!$this->privileges->contains($privilege)) {
            $this->privileges[] = $privilege;
            $privilege->setIntervention($this);
        }

        return $this;
    }

    public function removePrivilege(Privilege $privilege): self
    {
        if ($this->privileges->removeElement($privilege)) {
            // set the owning side to null (unless already changed)
            if ($privilege->getIntervention() === $this) {
                $privilege->setIntervention(null);
            }
        }

        return $this;
    }

    public function getPlanning(): ?Planning
    {
        return $this->planning;
    }

    public function setPlanning(?Planning $planning): self
    {
        $this->planning = $planning;

        return $this;
    }

    public function getEquipement(): ?Equipement
    {
        return $this->equipement;
    }

    public function setEquipement(?Equipement $equipement): self
    {
        $this->equipement = $equipement;

        return $this;
    }

    public function getClientPayeurTiers(): ?Client
    {
        return $this->client_payeur_tiers;
    }

    public function setClientPayeurTiers(?Client $client_payeur_tiers): self
    {
        $this->client_payeur_tiers = $client_payeur_tiers;

        return $this;
    }

    public function getAvisPassage(): ?bool
    {
        return $this->avis_passage;
    }

    public function setAvisPassage(?bool $avis_passage): self
    {
        $this->avis_passage = $avis_passage;

        return $this;
    }

    public function getAvisPassageMail(): ?bool
    {
        return $this->avis_passage_mail;
    }

    public function setAvisPassageMail(?bool $avis_passage_mail): self
    {
        $this->avis_passage_mail = $avis_passage_mail;

        return $this;
    }

    public function getMemo(): ?string
    {
        return $this->memo;
    }

    public function setMemo(?string $memo): self
    {
        $this->memo = $memo;

        return $this;
    }

    public function getTemps(): ?int
    {
        return $this->temps;
    }

    public function setTemps(?int $temps): self
    {
        $this->temps = $temps;

        return $this;
    }

    public function getInterventionMotif(): ?InterventionMotif
    {
        return $this->intervention_motif;
    }

    public function setInterventionMotif(?InterventionMotif $intervention_motif): self
    {
        $this->intervention_motif = $intervention_motif;

        return $this;
    }

    public function getHoraireAControler(): ?bool
    {
        return $this->horaire_a_controler;
    }

    public function setHoraireAControler(?bool $horaire_a_controler): self
    {
        $this->horaire_a_controler = $horaire_a_controler;

        return $this;
    }

    public function getMesureCo(): ?int
    {
        return $this->mesure_co;
    }

    public function setMesureCo(?int $mesure_co): self
    {
        $this->mesure_co = $mesure_co;

        return $this;
    }

    public function getObservations(): ?string
    {
        return $this->observations;
    }

    public function setObservations(?string $observations): self
    {
        $this->observations = $observations;

        return $this;
    }

    public function getCgvAcceptees(): ?bool
    {
        return $this->cgv_acceptees;
    }

    public function setCgvAcceptees(?bool $cgv_acceptees): self
    {
        $this->cgv_acceptees = $cgv_acceptees;

        return $this;
    }

    public function getCommentaireClient(): ?string
    {
        return $this->commentaire_client;
    }

    public function setCommentaireClient(?string $commentaire_client): self
    {
        $this->commentaire_client = $commentaire_client;

        return $this;
    }

    public function getTypeEnvoiRapport(): ?TypeEnvoi
    {
        return $this->type_envoi_rapport;
    }

    public function setTypeEnvoiRapport(?TypeEnvoi $type_envoi_rapport): self
    {
        $this->type_envoi_rapport = $type_envoi_rapport;

        return $this;
    }

    public function getMotifModifCodeInt(): ?string
    {
        return $this->motif_modif_code_int;
    }

    public function setMotifModifCodeInt(?string $motif_modif_code_int): self
    {
        $this->motif_modif_code_int = $motif_modif_code_int;

        return $this;
    }

    public function getCliRefusSignature(): ?bool
    {
        return $this->cli_refus_signature;
    }

    public function setCliRefusSignature(?bool $cli_refus_signature): self
    {
        $this->cli_refus_signature = $cli_refus_signature;

        return $this;
    }

    public function getCommentaireRefusSignature(): ?string
    {
        return $this->commentaire_refus_signature;
    }

    public function setCommentaireRefusSignature(?string $commentaire_refus_signature): self
    {
        $this->commentaire_refus_signature = $commentaire_refus_signature;

        return $this;
    }

    public function getFichePapierLiee(): ?int
    {
        return $this->fiche_papier_liee;
    }

    public function setFichePapierLiee(?int $fiche_papier_liee): self
    {
        $this->fiche_papier_liee = $fiche_papier_liee;

        return $this;
    }

    public function getContratTarif(): ?ContratTarif
    {
        return $this->contrat_tarif;
    }

    public function setContrat(?ContratTarif $contrat_tarif): self
    {
        $this->contrat_tarif = $contrat_tarif;

        return $this;
    }

    public function getEncaissementEffectue(): ?int
    {
        return $this->encaissement_effectue;
    }

    public function setEncaissementEffectue(?int $encaissement_effectue): self
    {
        $this->encaissement_effectue = $encaissement_effectue;

        return $this;
    }

    public function getUtilisateurValidationTechnique(): ?Utilisateur
    {
        return $this->utilisateur_validation_technique;
    }

    public function setUtilisateurValidationTechnique(?Utilisateur $utilisateur_validation_technique): self
    {
        $this->utilisateur_validation_technique = $utilisateur_validation_technique;

        return $this;
    }

    public function getDateValidationTechnique(): ?\DateTimeInterface
    {
        return $this->date_validation_technique;
    }

    public function setDateValidationTechnique(?\DateTimeInterface $date_validation_technique): self
    {
        $this->date_validation_technique = $date_validation_technique;

        return $this;
    }

    public function getCommentaireTechnique(): ?string
    {
        return $this->commentaire_technique;
    }

    public function setCommentaireTechnique(?string $commentaire_technique): self
    {
        $this->commentaire_technique = $commentaire_technique;

        return $this;
    }

    public function getUtilisateurValidationAdm(): ?Utilisateur
    {
        return $this->utilisateur_validation_adm;
    }

    public function setUtilisateurValidationAdm(?Utilisateur $utilisateur_validation_adm): self
    {
        $this->utilisateur_validation_adm = $utilisateur_validation_adm;

        return $this;
    }

    public function getDateValidationAdm(): ?\DateTimeInterface
    {
        return $this->date_validation_adm;
    }

    public function setDateValidationAdm(?\DateTimeInterface $date_validation_adm): self
    {
        $this->date_validation_adm = $date_validation_adm;

        return $this;
    }

    public function getEntretien(): ?bool
    {
        return $this->entretien;
    }

    public function setEntretien(?bool $entretien): self
    {
        $this->entretien = $entretien;

        return $this;
    }

    public function getSite(): ?Site
    {
        return $this->site;
    }

    public function setSite(?Site $site): self
    {
        $this->site = $site;

        return $this;
    }

    /**
     * @SerializedName("nom_complet_agent")
     * @Groups({"api"})
     */
    public function getNomCompletAgent()
    {
        return $this->getPlanning()->getUtilisateurAgent()->getNomComplet();
    }

    public function getTypeVisiteIntervention(): ?TypeVisiteIntervention
    {
        return $this->type_visite_intervention;
    }

    public function setTypeVisiteIntervention(?TypeVisiteIntervention $type_visite_intervention): self
    {
        $this->type_visite_intervention = $type_visite_intervention;

        return $this;
    }

    /**
     * @return Collection<int, ContratResiliation>
     */
    public function getContratResiliations(): Collection
    {
        return $this->contratResiliations;
    }

    public function addContratResiliation(ContratResiliation $contratResiliation): self
    {
        if (!$this->contratResiliations->contains($contratResiliation)) {
            $this->contratResiliations[] = $contratResiliation;
            $contratResiliation->setIntervention($this);
        }

        return $this;
    }

    public function removeContratResiliation(ContratResiliation $contratResiliation): self
    {
        if ($this->contratResiliations->removeElement($contratResiliation)) {
            // set the owning side to null (unless already changed)
            if ($contratResiliation->getIntervention() === $this) {
                $contratResiliation->setIntervention(null);
            }
        }

        return $this;
    }

    public function getFormattedInterventionForResiliation() {
        return $this->getId() . '-' . $this->getPlanning()->getDate()->format('Y-m-d H:i:s') . '-' . (($this->getPlanning()->getTypePlanificationInit()) ? $this->getPlanning()->getTypePlanificationInit()->getLibelle() : '');
    }

    /**
     * @return Collection<int, EquipementMesure>
     */
    public function getEquipementMesures(): Collection
    {
        return $this->equipementMesures;
    }

    public function addEquipementMesure(EquipementMesure $equipementMesure): self
    {
        if (!$this->equipementMesures->contains($equipementMesure)) {
            $this->equipementMesures[] = $equipementMesure;
            $equipementMesure->setIntervention($this);
        }

        return $this;
    }

    public function removeEquipementMesure(EquipementMesure $equipementMesure): self
    {
        if ($this->equipementMesures->removeElement($equipementMesure)) {
            // set the owning side to null (unless already changed)
            if ($equipementMesure->getIntervention() === $this) {
                $equipementMesure->setIntervention(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, InterventionMedia>
     */
    public function getInterventionMedias(): Collection
    {
        return $this->interventionMedias;
    }

    public function addInterventionMedia(InterventionMedia $interventionMedia): self
    {
        if (!$this->interventionMedias->contains($interventionMedia)) {
            $this->interventionMedias[] = $interventionMedia;
            $interventionMedia->setIntervention($this);
        }

        return $this;
    }

    public function removeInterventionMedia(InterventionMedia $interventionMedia): self
    {
        if ($this->interventionMedias->removeElement($interventionMedia)) {
            // set the owning side to null (unless already changed)
            if ($interventionMedia->getIntervention() === $this) {
                $interventionMedia->setIntervention(null);
            }
        }

        return $this;
    }

    public function getInterventionClasseEnergetique(){
        return $this->interventionClasseEnergetique;
    }

    public function setInterventionClasseEnergetique(?InterventionClasseEnergetique $interventionClasseEnergetique){
        $this->interventionClasseEnergetique = $interventionClasseEnergetique;

        return $this;
    }

    public function getStack()
    {
        return stream_get_contents($this->stack);
    }

    public function setStack($stack): self
    {
        $this->stack = $stack;

        return $this;
    }


    /**
     * @return Collection<int, Produit>
     */
    public function getForfaits()
    {
        return $this->forfaits;
    }

    public function setForfaits($forfaits): self
    {
        foreach ($forfaits as $forfait){
            $this->forfaits[] = $forfait;
        }

        return $this;
    }


    /**
     * @return Collection<int, Produit>
     */
    public function getDeplacement()
    {
        return $this->deplacement;
    }

    public function setDeplacement($deplacement): self
    {
        $this->deplacement = $deplacement;
        return $this;
    }

    /**
     * @return Collection<int, FactureLigne>
     */
    public function getProduits()
    {
        return $this->produits;
    }

    public function setProduits($produits): self
    {
        $this->produits = $produits;
        return $this;
    }

    /**
     * @return Collection<int, FactureLigne>
     */
    public function getPiecesHistorique()
    {
        return $this->piecesHistorique;
    }

    public function setPiecesHistorique($piecesHistorique): self
    {
        $this->piecesHistorique = $piecesHistorique;
        return $this;
    }

    /**
     * @return Collection<int, Anomalie>
     */
    public function getAnomalieHistorique()
    {
        return $this->anomalieHistorique;
    }

    public function setAnomalieHistorique($anomalieHistorique): self
    {
        $this->anomalieHistorique = $anomalieHistorique;
        return $this;
    }


    /**
     * @return Collection<int, ContratTarif>
     */
    public function getContratTarifs()
    {
        return $this->contratTarifs;
    }

    public function setContratTarifs($contratTarifs): self
    {
        $this->contratTarifs = $contratTarifs;
        return $this;
    }

    public function getAttestationEntretien(): ?AttestationEntretien
    {
        return $this->attestation_entretien;
    }

    public function setAttestationEntretien(?AttestationEntretien $attestation_entretien): self
    {
        $this->attestation_entretien = $attestation_entretien;

        return $this;
    }

    public function getZud(): ?bool
    {
        return $this->zud;
    }

    public function setZud(?bool $zud): self
    {
        $this->zud = $zud;

        return $this;
    }

    public function getMoyenPaiement(): ?MoyenPaiement
    {
        return $this->moyenPaiement;
    }

    public function setMoyenPaiement(?MoyenPaiement $moyenPaiement): self
    {
        $this->moyenPaiement = $moyenPaiement;

        return $this;
    }

    public function getRetour(): ?Retour
    {
        return $this->retour;
    }

    public function setRetour(?Retour $retour): self
    {
        $this->retour = $retour;

        return $this;
    }

    /**
     * @return Collection<int, InterventionAnomalie>
     */
    public function getInterventionAnomalies(): Collection
    {
        return $this->interventionAnomalies;
    }

    /**
     */
    public function getAnomaliesArray()
    {
        $tabAnomalies = [];
        if ($this->getInterventionAnomalies()) {
            foreach ($this->getInterventionAnomalies() as $interventionAnomaly) {
                $tabAnomalies[] = $interventionAnomaly->getAnomalie()->getAnnotation();
            }
        }
        return $tabAnomalies;
    }

    public function addInterventionAnomaly(InterventionAnomalie $interventionAnomaly): self
    {
        if (!$this->interventionAnomalies->contains($interventionAnomaly)) {
            $this->interventionAnomalies[] = $interventionAnomaly;
            $interventionAnomaly->setIntervention($this);
        }

        return $this;
    }

    public function removeInterventionAnomaly(InterventionAnomalie $interventionAnomaly): self
    {
        if ($this->interventionAnomalies->removeElement($interventionAnomaly)) {
            // set the owning side to null (unless already changed)
            if ($interventionAnomaly->getIntervention() === $this) {
                $interventionAnomaly->setIntervention(null);
            }
        }

        return $this;
    }

    public function getTypeValidationTechnique(): ?InterventionTypeValidation
    {
        return $this->type_validation_technique;
    }

    public function setTypeValidationTechnique(?InterventionTypeValidation $type_validation_technique): self
    {
        $this->type_validation_technique = $type_validation_technique;

        return $this;
    }

    public function getTypeValidationAdm(): ?InterventionTypeValidation
    {
        return $this->type_validation_adm;
    }

    public function setTypeValidationAdm(?InterventionTypeValidation $type_validation_adm): self
    {
        $this->type_validation_adm = $type_validation_adm;

        return $this;
    }

    public function getMarqueAppareil(): ?string
    {
        return $this->marque_appareil;
    }

    public function setMarqueAppareil(?string $marque_appareil): self
    {
        $this->marque_appareil = $marque_appareil;

        return $this;
    }

    public function getModeleAppareil(): ?string
    {
        return $this->modele_appareil;
    }

    public function setModeleAppareil(?string $modele_appareil): self
    {
        $this->modele_appareil = $modele_appareil;

        return $this;
    }

    public function getEmailEnvoiRapport(): ?string
    {
        return $this->email_envoi_rapport;
    }

    public function setEmailEnvoiRapport(?string $email_envoi_rapport): self
    {
        $this->email_envoi_rapport = $email_envoi_rapport;

        return $this;
    }

    /**
     * @return Collection<int, InterventionAnnulation>
     */
    public function getInterventionAnnulations(): Collection
    {
        return $this->interventionAnnulations;
    }

    public function addInterventionAnnulation(InterventionAnnulation $interventionAnnulation): self
    {
        if (!$this->interventionAnnulations->contains($interventionAnnulation)) {
            $this->interventionAnnulations[] = $interventionAnnulation;
            $interventionAnnulation->setIntervention($this);
        }

        return $this;
    }

    public function removeInterventionAnnulation(InterventionAnnulation $interventionAnnulation): self
    {
        if ($this->interventionAnnulations->removeElement($interventionAnnulation)) {
            // set the owning side to null (unless already changed)
            if ($interventionAnnulation->getIntervention() === $this) {
                $interventionAnnulation->setIntervention(null);
            }
        }

        return $this;
    }

    public function getTypePlanification(): ?TypePlanification
    {
        return $this->type_planification;
    }

    public function setTypePlanification(?TypePlanification $type_planification): self
    {
        $this->type_planification = $type_planification;

        return $this;
    }

    public function getDateDernierControleEtancheite(): ?\DateTimeInterface
    {
        return $this->date_dernier_controle_etancheite;
    }

    public function setDateDernierControleEtancheite(?\DateTimeInterface $date_dernier_controle_etancheite): self
    {
        $this->date_dernier_controle_etancheite = $date_dernier_controle_etancheite;

        return $this;
    }

    public function getFuite(): ?bool
    {
        return $this->fuite;
    }

    public function setFuite(?bool $fuite): self
    {
        $this->fuite = $fuite;

        return $this;
    }

    public function getFuiteNb(): ?int
    {
        return $this->fuite_nb;
    }

    public function setFuiteNb(?int $fuite_nb): self
    {
        $this->fuite_nb = $fuite_nb;

        return $this;
    }

    public function getReparation(): ?string
    {
        return $this->reparation;
    }

    public function setReparation(?string $reparation): self
    {
        $this->reparation = $reparation;

        return $this;
    }

    public function getCerfa(): ?bool
    {
        return $this->cerfa;
    }

    public function setCerfa(?bool $cerfa): self
    {
        $this->cerfa = $cerfa;

        return $this;
    }

    public function getEnvoiFacture(): ?bool
    {
        return $this->envoi_facture;
    }

    public function setEnvoiFacture(?bool $envoi_facture): self
    {
        $this->envoi_facture = $envoi_facture;

        return $this;
    }

    /**
     * @return Collection<int, InterventionMesure>
     */
    public function getInterventionMesures(): Collection
    {
        return $this->interventionMesures;
    }

    public function addInterventionMesure(InterventionMesure $interventionMesure): self
    {
        if (!$this->interventionMesures->contains($interventionMesure)) {
            $this->interventionMesures[] = $interventionMesure;
            $interventionMesure->setIntervention($this);
        }

        return $this;
    }

    public function removeInterventionMesure(InterventionMesure $interventionMesure): self
    {
        if ($this->interventionMesures->removeElement($interventionMesure)) {
            // set the owning side to null (unless already changed)
            if ($interventionMesure->getIntervention() === $this) {
                $interventionMesure->setIntervention(null);
            }
        }

        return $this;
    }

    public function estPriseContrat() {
        foreach ($this->factures as $facture) {
            if ($facture->getPriseContrat() == true) return true;
        }
        return false;
    }

    /**
     * @return Collection<int, InterventionDocument>
     */
    public function getInterventionDocuments(): Collection
    {
        return $this->interventionDocuments;
    }

    public function addInterventionDocument(InterventionDocument $interventionDocument): self
    {
        if (!$this->interventionDocuments->contains($interventionDocument)) {
            $this->interventionDocuments[] = $interventionDocument;
            $interventionDocument->setIntervention($this);
        }

        return $this;
    }

    public function removeInterventionDocument(InterventionDocument $interventionDocument): self
    {
        if ($this->interventionDocuments->removeElement($interventionDocument)) {
            // set the owning side to null (unless already changed)
            if ($interventionDocument->getIntervention() === $this) {
                $interventionDocument->setIntervention(null);
            }
        }

        return $this;
    }

    public function getLigneDeplacement(): ?FactureLigne
    {
        foreach ($this->getFactures() as $facture) {
            foreach ($facture->getFactureLignes() as $ligne) {
                if ($ligne->getProduit() && $ligne->getProduit()->getCode() === 'DEPL') {
                    return $ligne;
                }
            }
        }
        return null;
    }

    public function getLigneMO(): ?FactureLigne
    {
        foreach ($this->getFactures() as $facture) {
            foreach ($facture->getFactureLignes() as $ligne) {
                if ($ligne->getProduit() && $ligne->getProduit()->getCode() === 'MO') {
                    return $ligne;
                }
            }
        }
        return null;
    }

    public function getDevisLigneDeplacement(): ?FactureLigne
    {
        foreach ($this->getDevis() as $devis) {
            foreach ($devis->getDevisLignes() as $ligne) {
                if ($ligne->getProduit() && $ligne->getProduit()->getCode() === 'DEPL') {
                    return $ligne;
                }
            }
        }
        return null;
    }

    public function getDevisLigneMO(): ?FactureLigne
    {
        foreach ($this->getDevis() as $devis) {
            foreach ($devis->getDevisLignes() as $ligne) {
                if ($ligne->getProduit() && $ligne->getProduit()->getCode() === 'MO') {
                    return $ligne;
                }
            }
        }
        return null;
    }

    public function getDataInterventionListeCas() {
        if($this->getEquipement() && $this->getEquipement()->getClientSouscripteur()){
            return $this->getEquipement()->getClientSouscripteur()->getNumeroClient() . ' - ' . $this->getEquipement()->getClientSouscripteur()->getIdentite(). ' - ' . $this->getEquipement()->getAdresse()->getLisibleAdresse();
        }
        else{
            return "Equipement inconnu";
        }
        return null;
    }

    public function getNumficheOracle(): ?int
    {
        return $this->numfiche_oracle;
    }

    public function setNumficheOracle(?int $numfiche_oracle): self
    {
        $this->numfiche_oracle = $numfiche_oracle;

        return $this;
    }

    /**
     * @return Collection<int, EquipementHauteur>
     */
    public function getEquipementHauteurs(): Collection
    {
        return $this->equipementHauteurs;
    }

    public function addEquipementHauteur(EquipementHauteur $equipementHauteur): self
    {
        if (!$this->equipementHauteurs->contains($equipementHauteur)) {
            $this->equipementHauteurs[] = $equipementHauteur;
            $equipementHauteur->setIntervention($this);
        }

        return $this;
    }

    public function removeEquipementHauteur(EquipementHauteur $equipementHauteur): self
    {
        if ($this->equipementHauteurs->removeElement($equipementHauteur)) {
            // set the owning side to null (unless already changed)
            if ($equipementHauteur->getIntervention() === $this) {
                $equipementHauteur->setIntervention(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, HistoriqueEquipementLocal>
     */
    public function getHistoriqueEquipementLocals(): Collection
    {
        return $this->historiqueEquipementLocals;
    }

    public function addHistoriqueEquipementLocal(HistoriqueEquipementLocal $historiqueEquipementLocal): self
    {
        if (!$this->historiqueEquipementLocals->contains($historiqueEquipementLocal)) {
            $this->historiqueEquipementLocals[] = $historiqueEquipementLocal;
            $historiqueEquipementLocal->setIntervention($this);
        }

        return $this;
    }

    public function removeHistoriqueEquipementLocal(HistoriqueEquipementLocal $historiqueEquipementLocal): self
    {
        if ($this->historiqueEquipementLocals->removeElement($historiqueEquipementLocal)) {
            // set the owning side to null (unless already changed)
            if ($historiqueEquipementLocal->getIntervention() === $this) {
                $historiqueEquipementLocal->setIntervention(null);
            }
        }

        return $this;
    }

    public function getNumBonCommande(): ?string
    {
        return $this->num_bon_commande;
    }

    public function setNumBonCommande(string $num_bon_commande): self
    {
        $this->num_bon_commande = $num_bon_commande;

        return $this;
    }
}
