<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Entity;

use App\Utils\Functions;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;


/**
 * @ORM\Entity(repositoryClass="App\Repository\UtilisateurRepository")
 * @ORM\Table(schema="sav")
 * @UniqueEntity(fields={"nom", "prenom"}, message="Ce nom et prénom sont déjà utilisés.")
 * @ORM\HasLifecycleCallbacks()
 *
 */
class Utilisateur implements UserInterface, PasswordAuthenticatedUserInterface
{
    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"api", "site_list", "site", "map", "planning"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"api", "site_list", "site", "map", "planning"})
     */
    private $nom;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"api", "site_list", "site", "map", "planning"})
     */
    private $prenom;

    /**
     * @ORM\Column(type="string", length=4, nullable=true)
     * @Groups({"site_list", "site", "map"})
     */
    private $initiales;

    /**
     * @ORM\ManyToOne(targetEntity=TypeLogin::class, inversedBy="utilisateurs")
     * @ORM\JoinColumn(nullable=false, name="idtype_login")
     * @Ignore()
     */
    private $type_login;

    /**
     * @var string
     *
     * @ORM\Column(type="string", unique=true, nullable=true)
     * @Assert\Length(min=2, max=50)
     * @Groups({"site_list"})
     */
    private $login;

    /**
     * @var string
     *
     * @ORM\Column(type="string", nullable=true)
     */
    private $password;

    /**
     * @ORM\Column(type="string", length=64, nullable=true)
     */
    private $cle_salage;

    /**
     * @ORM\ManyToOne(targetEntity=TypeUtilisateur::class, inversedBy="utilisateurs")
     * @ORM\JoinColumn(nullable=false, name="idtype_utilisateur")
     * @Ignore()
     */
    private $type_utilisateur;

    /**
     * @SerializedName("type_name")
     * @Groups({"site_list"})
     */
    public function getTypeName() {
        return $this->getTypeUtilisateur()->getLibelle();
    }

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $url_homepage;

    /**
     * @ORM\ManyToOne(targetEntity=Utilisateur::class, inversedBy="utilisateurs_conges")
     * @ORM\JoinColumn(name="idutilisateur_valide_conges")
     * @Ignore()
     */
    private $utilisateur_valide_conges;
    /**
     * @ORM\Column(type="date", nullable=true)
     * @Groups({"site_list"})
     */
    private $date_embauche;

    /**
     * @ORM\ManyToOne(targetEntity=Agence::class, inversedBy="utilisateurs")
     * @ORM\JoinColumn(name="idagence")
     * @Groups({"api"})
     */
    private $agence;

    /**
     * @ORM\Column(type="string", length=9, nullable=true)
     */
    private $code_client_agi;

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

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurFiltre::class, mappedBy="utilisateur", orphanRemoval=true)
     * @Ignore()
     */
    private $utilisateurFiltres;


    /**
     * @ORM\Column(type="json", nullable=true)
     */
    private $droits = [];

    /**
     * @ORM\ManyToOne(targetEntity=UtilisateurRole::class, inversedBy="utilisateurs")
     * @ORM\JoinColumn(nullable=false, name="idutilisateur_role")
     * @Ignore()
     */
    private $role;

    /**
     * @ORM\OneToMany(targetEntity="GroupeUtilisateur", mappedBy="utilisateur")
     * @Ignore()
     */
    private $groupesUtilisateur;

    /**
     * @ORM\OneToMany(targetEntity="TchatMessage", mappedBy="utilisateur")
     * @Ignore()
     */
    private $messages;

    /**
     * @ORM\OneToMany(targetEntity=Groupe::class, mappedBy="admin")
     * @Ignore()
     */
    private $groupes;

    /**
     * @ORM\OneToMany(targetEntity=Utilisateur::class, mappedBy="utilisateur_valide_conges")
     * @Ignore()
     */
    private $utilisateurs_conges;

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurAdresse::class, mappedBy="utilisateur")
     * @Ignore()
     */
    private $utilisateurAdresses;

    /**
     * @SerializedName("coordonnees")
     * @Groups({"map"})
     */
    public function getCoordonnees() {
        foreach ($this->utilisateurAdresses as $utilisateurAdresse) {
            if ($utilisateurAdresse->getActif())return $utilisateurAdresse->getAdresse()->getCoordonnees();
        }
        return null;
    }

    /**
     * @SerializedName("adresse")
     * @Groups({"site_list"})
     */
    public function getAdresse() {
        foreach ($this->utilisateurAdresses as $utilisateurAdresse) {
            if ($utilisateurAdresse->getActif()) return $utilisateurAdresse->getAdresse()->getLisibleAdresse();
        }
        return null;
    }

    /**
     * @Ignore()
     */
    public function getAdresseActive() {
        foreach ($this->utilisateurAdresses as $utilisateurAdresse) {
            if ($utilisateurAdresse->getActif()) return $utilisateurAdresse;
        }
        return null;
    }

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurEmail::class, mappedBy="utilisateur")
     * @Ignore()
     */
    private $utilisateurEmails;

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurTel::class, mappedBy="utilisateur")
     * @Ignore()
     */
    private $utilisateurTels;

    /**
     * @SerializedName("telephone")
     * @Groups({"site_list"})
     */
    public function getTelephone() {
        foreach ($this->utilisateurTels as $utilisateurTel) {
            return $utilisateurTel->getNumero();
        }
        return null;
    }

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurAffectation::class, mappedBy="utilisateur")
     * @Ignore()
     */
    private $utilisateurAffectations;

    /**
     * @SerializedName("poleLibelle")
     * @Groups({"site_list"})
     */
    public function getPoleLibelle() {
        foreach ($this->groupes as $groupe) {
            if ($groupe->getActif() && $groupe->getGroupeType() == GroupeType::ID_POLE) return $groupe->getNom();
        }
        return null;
    }

    /**
     * @Ignore()
     */
    public function getPole() {
        foreach ($this->utilisateur_affectations_planning as $agent_planning) {
            return $agent_planning;
        }
        return null;
    }

    /**
     * @SerializedName("groupe_pole")
     * @Groups({"planning"})
     */
    public function getPoleActif() {
        foreach ($this->groupesUtilisateur as $groupeUtilisateur) {
            $groupe = $groupeUtilisateur->getGroupe();
            if ($groupe->getActif() && $groupe->getGroupeType()->getId() == GroupeType::ID_POLE) return $groupe->getId();
        }
        return null;
    }

    /**
     * @SerializedName("profil_name")
     * @Groups({"site_list"})
     */
    public function getTypeProfil() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif()) return $utilisateurAffectation->getUtilisateurProfil()->getLibelle();
        }
        return null;
    }

    /**
     * @SerializedName("nom_responsable")
     * @Groups({"site_list"})
     */
    public function getNomResponsable() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif())
                return ($utilisateurAffectation->getUtilisateurReponsable()) ? $utilisateurAffectation->getUtilisateurReponsable()->getNomComplet() : null;
        }
        return null;
    }

    /**
     * @SerializedName("groupe_affectation")
     * @Groups({"site_list", "map", "planning"})
     */
    public function getIdGroupe() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif())
                return ($utilisateurAffectation->getUtilisateurReponsable()) ? $utilisateurAffectation->getUtilisateurReponsable()->getId() : null;
        }
        return null;
    }

    /**
     * @SerializedName("planifiable")
     * @Groups({"site_list", "map"})
     */
    public function getPlanifiable() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif())
                return ($utilisateurAffectation->getPlanifiable());
        }
        return false;
    }

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurAffectation::class, mappedBy="utilisateur_planning")
     * @Ignore()
     */
    private $utilisateur_affectations_planning;

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurAffectation::class, mappedBy="utilisateur_reponsable")
     * @Ignore()
     */
    private $utilisateur_affectations_responsable;

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurAffectation::class, mappedBy="utilisateur_binome")
     * @Ignore()
     */
    private $utilisateur_affectations_binome;

    /**
     * @ORM\OneToMany(targetEntity=UtilisateurSite::class, mappedBy="utilisateur", cascade={"persist"}, orphanRemoval=true)
     * @Ignore()
     */
    private $utilisateurSites;

    /**
     * @ORM\OneToMany(targetEntity=AgentQualification::class, mappedBy="utilisateur_agent")
     */
    private $agentQualifications;

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

    /**
     * @SerializedName("qualifications")
     * @Groups({"site_list"})
     */
    public function getQualifications() {
        $result = [];
        foreach ($this->agentQualifications as $agentQualification) {
            $result[] = $agentQualification->getEquipementFamille()->getLibelle();
        }
        return implode('<br>', $result);
    }


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

    /**
     * @ORM\OneToMany(targetEntity=AgentAppareil::class, mappedBy="utilisateur_agent", orphanRemoval=true)
     * @Ignore()
     */
    private $agentAppareils;

    /**
     * @Groups({"api"})
     */
    private $appareils;

    /**
     * @ORM\OneToMany(targetEntity=SectorisationVersion::class, mappedBy="utilisateur")
     * @Ignore()
     */
    private $sectorisationVersions;

    /**
     * @ORM\OneToMany(targetEntity=AgentSecteur::class, mappedBy="utilisateur_agent")
     * @Ignore()
     */
    private $agentSecteurs;

    /**
     * @ORM\OneToMany(targetEntity=AgentGps::class, mappedBy="utilisateur_agent")
     * @Ignore()
     */
    private $agentGps;

    /**
     * @ORM\OneToMany(targetEntity=Contrat::class, mappedBy="agent_souscription")
     * @Ignore()
     */
    private $contrats_agent_souscripteur;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity=LockEntites::class, mappedBy="utilisateur", orphanRemoval=true)
     * @Ignore()
     */
    private $lockEntites;

    /**
     * @ORM\Column(type="string", length=20, nullable=true)
     * @Groups({"site_list", "map"})
     */
    private $code_agent;

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

    /**
     * @ORM\OneToMany(targetEntity=InterventionStack::class, mappedBy="agent")
     */
    private $interventionStacks;

    /**
     * @ORM\OneToMany(targetEntity=Secteur::class, mappedBy="utilisateur_planning")
     */
    private $secteurs;

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


    /**
     * @SerializedName("derniere_pos")
     * @Groups({"map"})
     */
    public function getDernierePos() {
        foreach ($this->agentGps as $gps) {
            return [
                'coordonnees' => $gps->getCoordonnees(),
                'date_heure' => $gps->getDateHeure()
            ];
        }
        return null;
    }


    /** @SerializedName("roles_name")
     * @Groups({"site_list"})
     */
    public function getRolesName() {
        return ($this->role) ? strtoupper($this->role->getNom()) : 'ROLE_USER';
    }

    /** @SerializedName("isAgent")
     * @Groups({"site_list"})
     */
    public function isAgent() {
        return ($this->role) ? $this->role->isAgent() : false;
    }

    /** @SerializedName("nomComplet")
     * @Groups({"site_list", "site", "map"})
     */
    public function getNomComplet() {
        return $this->getPrenom() . ' ' . $this->getNom();
    }

    /** @SerializedName("nomPrenom")
     * @Groups({"site_list", "site", "map"})
     */
    public function getNomPrenom() {
        return $this->getNom() . ' ' . $this->getPrenom();
    }

    /** @SerializedName("codeNom")
     * @Groups({"map"})
     */
    public function getCodeNom() {
        return $this->getCodeAgent() . ' - ' . (!empty($this->getPrenom()) ? $this->getPrenom()[0] . '. ' : '') . $this->getNom();
    }

    /** @SerializedName("sitesListe")
     * @Groups({"site_list"})
     */
    public function getSitesListe() {
        $result = [];
        foreach ($this->getUtilisateurSites() as $utilisateurSite) {
            $result[] = $utilisateurSite->getSite()->getNom();
        }
        return implode(',', $result);
    }

    public function getSitesListeString() {
        $result = [];
        foreach ($this->getUtilisateurSites() as $utilisateurSite) {
            $result[] = $utilisateurSite->getSite()->getNom();
        }
        return "'" . implode ( "', '", $result ) . "'";
    }

    public function getSitesListeEntities() {
        $result = [];
        foreach ($this->getUtilisateurSites() as $utilisateurSite) {
            $result[] = $utilisateurSite->getSite();
        }
        return $result;
    }


    public function __construct()
    {
        $this->utilisateurFiltres = new ArrayCollection();
        $this->groupesUtilisateur = new ArrayCollection();
        $this->messages = new ArrayCollection();
        $this->groupes = new ArrayCollection();
        $this->utilisateurs_conges = new ArrayCollection();
        $this->utilisateurAdresses = new ArrayCollection();
        $this->utilisateurEmails = new ArrayCollection();
        $this->utilisateurTels = new ArrayCollection();
        $this->utilisateurAffectations = new ArrayCollection();
        $this->utilisateur_affectations_planning = new ArrayCollection();
        $this->utilisateur_affectations_responsable = new ArrayCollection();
        $this->utilisateur_affectations_binome = new ArrayCollection();
        $this->utilisateurSites = new ArrayCollection();
        $this->agentQualifications = new ArrayCollection();
        $this->agentRestrictions = new ArrayCollection();
        $this->agentAppareils = new ArrayCollection();
        $this->sectorisationVersions = new ArrayCollection();
        $this->agentSecteurs = new ArrayCollection();
        $this->agentGps = new ArrayCollection();
        $this->contrats_agent_souscripteur = new ArrayCollection();
        $this->interventions = new ArrayCollection();
        $this->plannings = new ArrayCollection();
        $this->lockEntites = new ArrayCollection();
        $this->historiqueEquipementLocals = new ArrayCollection();
        $this->interventionStacks = new ArrayCollection();
        $this->secteurs = new ArrayCollection();
        $this->planningHistoriqueModifications = new ArrayCollection();
    }

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

    public function getUserIdentifier(): string
    {
        return ($this->login) ? $this->login : '';
    }

    public function getUsername(): string
    {
        return $this->getUserIdentifier();
    }

    public function getLogin(): string
    {
        return $this->login;
    }

    public function setLogin(string $login): void
    {
        $this->login = $login;
    }

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function setPassword(string $password): void
    {
        $this->password = $password;
    }


    /**
     * Returns the salt that was originally used to encode the password.
     *
     * {@inheritdoc}
     */
    public function getSalt(): ?string
    {
        // We're using bcrypt in security.yaml to encode the password, so
        // the salt value is built-in and and you don't have to generate one
        // See https://en.wikipedia.org/wiki/Bcrypt

        return null;
    }

    /**
     * Removes sensitive data from the utilisateur.
     *
     * {@inheritdoc}
     */
    public function eraseCredentials(): void
    {
        // if you had a plainPassword property, you'd nullify it here
        // $this->plainPassword = null;
    }

    /**
     * {@inheritdoc}
     */
    public function __serialize(): array
    {
        // add $this->salt too if you don't use Bcrypt or Argon2i
        return [$this->id, $this->login, $this->password];
    }

    /**
     * {@inheritdoc}
     */
    public function __unserialize(array $data): void
    {
        // add $this->salt too if you don't use Bcrypt or Argon2i
        [$this->id, $this->login, $this->password] = $data;
    }

    /**
     * @return Collection|UtilisateurFiltre[]
     */
    public function getUtilisateurFiltres(): Collection
    {
        return $this->utilisateurFiltres;
    }

    public function addUtilisateurFiltre(UtilisateurFiltre $utilisateurFiltre): self
    {
        if (!$this->utilisateurFiltres->contains($utilisateurFiltre)) {
            $this->utilisateurFiltres[] = $utilisateurFiltre;
            $utilisateurFiltre->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurFiltre(UtilisateurFiltre $utilisateurFiltre): self
    {
        if ($this->utilisateurFiltres->removeElement($utilisateurFiltre)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurFiltre->getUtilisateur() === $this) {
                $utilisateurFiltre->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * Returns the roles or permissions granted to the utilisateur for security.
     */
    public function getRoles(): array
    {
        $rolesLibelle = [];
        // guarantees that a utilisateur always has at least one role for security
        $rolesLibelle[] = (empty($this->role)) ? 'ROLE_USER' : $this->role->getLibelle();

        return array_unique($rolesLibelle);
    }

    public function getRole(): ?UtilisateurRole
    {
        return $this->role;
    }

    public function setRole(?UtilisateurRole $role): self
    {
        $this->role = $role;

        return $this;
    }


    public function getNom(): ?string
    {
        return $this->nom;
    }

    public function setNom(string $nom): self
    {
        $this->nom = strtoupper($nom);

        return $this;
    }

    public function getPrenom(): ?string
    {
        return $this->prenom;
    }

    public function setPrenom(?string $prenom): self
    {
        $this->prenom = $prenom;

        return $this;
    }

    public function getUrlHomepage(): ?string
    {
        return $this->url_homepage;
    }

    public function setUrlHomepage(?string $home): self
    {
        $this->url_homepage = $home;

        return $this;
    }

    public function getDroits(): ?array
    {
        return $this->droits;
    }

    public function setDroits(?array $droits): self
    {
        $this->droits = $droits;

        return $this;
    }

    /**
     * @return Collection|GroupeUtilisateur[]
     */
    public function getGroupesUtilisateur(): Collection
    {
        return $this->groupesUtilisateur;
    }

    public function addParticipant(GroupeUtilisateur $groupeUtilisateur): self
    {
        if (!$this->groupesUtilisateur->contains($groupeUtilisateur)) {
            $this->groupesUtilisateur[] = $groupeUtilisateur;
            $groupeUtilisateur->setUtilisateur($this);
        }

        return $this;
    }

    /**
     * @Ignore()
     */
    public function setSites($sites) {
      $this->handleSites($sites);
    }

    public function handleSites($sites) {
        $sitesAdd = array_diff($sites, $this->getSites());

        foreach ($this->getUtilisateurSites() as $utilisateurSite) {
            if (!in_array($utilisateurSite->getSite(), $sites)){
                $this->removeUtilisateurSite($utilisateurSite);
            }
        }

        foreach ($sitesAdd as $site) {
            $utilisateurSite = new UtilisateurSite();
            $utilisateurSite->setUtilisateur($this)->setSite($site);
            $this->addUtilisateurSite($utilisateurSite);
        }
    }

    public function getSites() {
        $result = [];
        foreach ($this->getUtilisateurSites() as $utilisateurSite) {
           $result[] = $utilisateurSite->getSite();
        }
        return $result;
    }

    public function removeParticipant(GroupeUtilisateur $groupeUtilisateur): self
    {
        if ($this->groupesUtilisateur->removeElement($groupeUtilisateur)) {
            // set the owning side to null (unless already changed)
            if ($groupeUtilisateur->getUtilisateur() === $this) {
                $groupeUtilisateur->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Message[]
     */
    public function getMessages(): Collection
    {
        return $this->messages;
    }

    public function addMessage(TchatMessage $message): self
    {
        if (!$this->messages->contains($message)) {
            $this->messages[] = $message;
            $message->setUtilisateur($this);
        }

        return $this;
    }

    public function removeMessage(TchatMessage $message): self
    {
        if ($this->messages->removeElement($message)) {
            // set the owning side to null (unless already changed)
            if ($message->getUtilisateur() === $this) {
                $message->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Groupe[]
     */
    public function getGroupes(): Collection
    {
        return $this->groupes;
    }

    public function addGroupe(Groupe $groupe): self
    {
        if (!$this->groupes->contains($groupe)) {
            $this->groupes[] = $groupe;
            $groupe->setAdmin($this);
        }

        return $this;
    }

    public function removeGroupe(Groupe $groupe): self
    {
        if ($this->groupes->removeElement($groupe)) {
            // set the owning side to null (unless already changed)
            if ($groupe->getAdmin() === $this) {
                $groupe->setAdmin(null);
            }
        }

        return $this;
    }

    public function __toString()
    {
        return $this->getPrenom() . ' ' . $this->getNom();
    }

    public function getTokenMobilite(): ?string
    {
        return $this->token_mobilite;
    }

    public function setTokenMobilite(?string $token_mobilite): self
    {
        $this->token_mobilite = $token_mobilite;

        return $this;
    }

    /**
     * @return TypeLogin|null
     * @Ignore()
     */
    public function getTypeLogin(): ?TypeLogin
    {
        return $this->type_login;
    }

    public function setTypeLogin(?TypeLogin $type_login): self
    {
        $this->type_login = $type_login;

        return $this;
    }

    public function getCleSalage(): ?string
    {
        return $this->cle_salage;
    }

    public function setCleSalage(?string $cle_salage): self
    {
        $this->cle_salage = $cle_salage;

        return $this;
    }

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

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

        return $this;
    }

    public function getCodeClientAgi(): ?string
    {
        return $this->code_client_agi;
    }

    public function setCodeClientAgi(?string $code_client_agi): self
    {
        $this->code_client_agi = $code_client_agi;

        return $this;
    }

    /**
     * @return TypeUtilisateur|null
     * @Ignore()
     */
    public function getTypeUtilisateur(): ?TypeUtilisateur
    {
        return $this->type_utilisateur;
    }

    public function setTypeUtilisateur(?TypeUtilisateur $type_utilisateur): self
    {
        $this->type_utilisateur = $type_utilisateur;

        return $this;
    }

    public function getAgence(): ?Agence
    {
        return $this->agence;
    }

    public function setAgence(?Agence $agence): self
    {
        $this->agence = $agence;

        return $this;
    }

    /**
     * @return Utilisateur|null
     * @Ignore()
     */
    public function getUtilisateurValideConges(): ?self
    {
        return $this->utilisateur_valide_conges;
    }

    public function setUtilisateurValideConges(?self $utilisateur_valide_conges): self
    {
        $this->utilisateur_valide_conges = $utilisateur_valide_conges;

        return $this;
    }

    /**
     * @return Collection|self[]
     * @Ignore()
     */
    public function getUtilisateursConges(): Collection
    {
        return $this->utilisateurs_conges;
    }

    public function addUtilisateursConge(self $utilisateursConge): self
    {
        if (!$this->utilisateurs_conges->contains($utilisateursConge)) {
            $this->utilisateurs_conges[] = $utilisateursConge;
            $utilisateursConge->setUtilisateurValideConges($this);
        }

        return $this;
    }

    public function removeUtilisateursConge(self $utilisateursConge): self
    {
        if ($this->utilisateurs_conges->removeElement($utilisateursConge)) {
            // set the owning side to null (unless already changed)
            if ($utilisateursConge->getUtilisateurValideConges() === $this) {
                $utilisateursConge->setUtilisateurValideConges(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurAdresse[]
     * @Ignore()
     */
    public function getUtilisateurAdresses(): Collection
    {
        return $this->utilisateurAdresses;
    }

    public function addUtilisateurAdress(UtilisateurAdresse $utilisateurAdress): self
    {
        if (!$this->utilisateurAdresses->contains($utilisateurAdress)) {
            $this->utilisateurAdresses[] = $utilisateurAdress;
            $utilisateurAdress->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurAdress(UtilisateurAdresse $utilisateurAdress): self
    {
        if ($this->utilisateurAdresses->removeElement($utilisateurAdress)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurAdress->getUtilisateur() === $this) {
                $utilisateurAdress->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurEmail[]
     * @Ignore()
     */
    public function getUtilisateurEmails(): Collection
    {
        return $this->utilisateurEmails;
    }

    /**
     * @Ignore()
     */
    public function getEmailPerso() {
        foreach ($this->utilisateurEmails as $utilisateurEmail) {
            if ($utilisateurEmail->getTypeEmail()->getId() == TypeEmail::ID_EMAIL_PERSO)
                return $utilisateurEmail;
        }
        return null;
    }


    public function addUtilisateurEmail(UtilisateurEmail $utilisateurEmail): self
    {
        if (!$this->utilisateurEmails->contains($utilisateurEmail)) {
            $this->utilisateurEmails[] = $utilisateurEmail;
            $utilisateurEmail->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurEmail(UtilisateurEmail $utilisateurEmail): self
    {
        if ($this->utilisateurEmails->removeElement($utilisateurEmail)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurEmail->getUtilisateur() === $this) {
                $utilisateurEmail->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurTel[]
     * @Ignore()
     */
    public function getUtilisateurTels(): Collection
    {
        return $this->utilisateurTels;
    }

    /**
     * @Ignore()
     */
    public function getTelPerso() {
        foreach($this->utilisateurTels as $utilisateurTel) {
            if ($utilisateurTel->getTypeTel()->getId() == TypeTel::ID_TEL_PORTABLE) {
                return $utilisateurTel;
            }
        }
        return null;
    }

    /**
     * @Ignore()
     */
    public function getTelPro() {
        foreach($this->utilisateurTels as $utilisateurTel) {
            if ($utilisateurTel->getTypeTel()->getId() == TypeTel::ID_TEL_BUREAU) {
                return $utilisateurTel;
            }
        }
        return null;
    }

    public function addUtilisateurTel(UtilisateurTel $utilisateurTel): self
    {
        if (!$this->utilisateurTels->contains($utilisateurTel)) {
            $this->utilisateurTels[] = $utilisateurTel;
            $utilisateurTel->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurTel(UtilisateurTel $utilisateurTel): self
    {
        if ($this->utilisateurTels->removeElement($utilisateurTel)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurTel->getUtilisateur() === $this) {
                $utilisateurTel->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurAffectation[]
     * @Ignore()
     */
    public function getUtilisateurAffectations(): Collection
    {
        return $this->utilisateurAffectations;
    }

    /**
     * @Ignore()
     */
    public function getActiveUtilisateurAffectation() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif() == true) return $utilisateurAffectation;
        }
        return null;
    }

    /**
     * @Ignore()
     */
    public function getNextAffectation() {
        foreach ($this->utilisateurAffectations as $utilisateurAffectation) {
            if ($utilisateurAffectation->getActif() == false
                && is_null($utilisateurAffectation->getFinEffet())
                && $utilisateurAffectation->getDebutEffet() >= new DateTime()
            ) return $utilisateurAffectation;
        }
        return null;
    }

    public function addUtilisateurAffectation(UtilisateurAffectation $utilisateurAffectation): self
    {
        if (!$this->utilisateurAffectations->contains($utilisateurAffectation)) {
            $this->utilisateurAffectations[] = $utilisateurAffectation;
            $utilisateurAffectation->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurAffectation(UtilisateurAffectation $utilisateurAffectation): self
    {
        if ($this->utilisateurAffectations->removeElement($utilisateurAffectation)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurAffectation->getUtilisateur() === $this) {
                $utilisateurAffectation->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurAffectation[]
     * @Ignore()
     */
    public function getUtilisateurAffectationsPlanning(): Collection
    {
        return $this->utilisateur_affectations_planning;
    }

    public function addUtilisateurAffectationsPlanning(UtilisateurAffectation $utilisateurAffectationsPlanning): self
    {
        if (!$this->utilisateur_affectations_planning->contains($utilisateurAffectationsPlanning)) {
            $this->utilisateur_affectations_planning[] = $utilisateurAffectationsPlanning;
            $utilisateurAffectationsPlanning->setUtilisateurPlanning($this);
        }

        return $this;
    }

    public function removeUtilisateurAffectationsPlanning(UtilisateurAffectation $utilisateurAffectationsPlanning): self
    {
        if ($this->utilisateur_affectations_planning->removeElement($utilisateurAffectationsPlanning)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurAffectationsPlanning->getUtilisateurPlanning() === $this) {
                $utilisateurAffectationsPlanning->setUtilisateurPlanning(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurAffectation[]
     * @Ignore()
     */
    public function getUtilisateurAffectationsResponsable(): Collection
    {
        return $this->utilisateur_affectations_responsable;
    }

    public function addUtilisateurAffectationsResponsable(UtilisateurAffectation $utilisateurAffectationsResponsable): self
    {
        if (!$this->utilisateur_affectations_responsable->contains($utilisateurAffectationsResponsable)) {
            $this->utilisateur_affectations_responsable[] = $utilisateurAffectationsResponsable;
            $utilisateurAffectationsResponsable->setUtilisateurReponsable($this);
        }

        return $this;
    }

    public function removeUtilisateurAffectationsResponsable(UtilisateurAffectation $utilisateurAffectationsResponsable): self
    {
        if ($this->utilisateur_affectations_responsable->removeElement($utilisateurAffectationsResponsable)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurAffectationsResponsable->getUtilisateurReponsable() === $this) {
                $utilisateurAffectationsResponsable->setUtilisateurReponsable(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurAffectation[]
     * @Ignore()
     */
    public function getUtilisateurAffectationsBinome(): Collection
    {
        return $this->utilisateur_affectations_binome;
    }

    public function addUtilisateurAffectationsBinome(UtilisateurAffectation $utilisateurAffectationsBinome): self
    {
        if (!$this->utilisateur_affectations_binome->contains($utilisateurAffectationsBinome)) {
            $this->utilisateur_affectations_binome[] = $utilisateurAffectationsBinome;
            $utilisateurAffectationsBinome->setUtilisateurBinome($this);
        }

        return $this;
    }

    public function removeUtilisateurAffectationsBinome(UtilisateurAffectation $utilisateurAffectationsBinome): self
    {
        if ($this->utilisateur_affectations_binome->removeElement($utilisateurAffectationsBinome)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurAffectationsBinome->getUtilisateurBinome() === $this) {
                $utilisateurAffectationsBinome->setUtilisateurBinome(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|UtilisateurSite[]
     * @Ignore()
     */
    public function getUtilisateurSites(): Collection
    {
        return $this->utilisateurSites;
    }

    public function addUtilisateurSite(UtilisateurSite $utilisateurSite): self
    {
        if (!$this->utilisateurSites->contains($utilisateurSite)) {
            $this->utilisateurSites[] = $utilisateurSite;
            $utilisateurSite->setUtilisateur($this);
        }

        return $this;
    }

    public function removeUtilisateurSite(UtilisateurSite $utilisateurSite): self
    {
        if ($this->utilisateurSites->removeElement($utilisateurSite)) {
            // set the owning side to null (unless already changed)
            if ($utilisateurSite->getUtilisateur() === $this) {
                $utilisateurSite->setUtilisateur(null);
            }
        }

        return $this;
    }

    public function getInitiales(): ?string
    {
        return $this->initiales;
    }

    public function setInitiales(?string $initiales): self
    {
        $this->initiales = $initiales;

        return $this;
    }

    /**
     * @return Collection|AgentQualification[]
     * @SerializedName("qualifications")
     * @Groups({"planning"})
     */
    public function getAgentQualifications(): Collection
    {
        return $this->agentQualifications;
    }

    public function addAgentQualification(AgentQualification $agentQualification): self
    {
        if (!$this->agentQualifications->contains($agentQualification)) {
            $this->agentQualifications[] = $agentQualification;
            $agentQualification->setIdutilisateurAgent($this);
        }

        return $this;
    }

    public function removeAgentQualification(AgentQualification $agentQualification): self
    {
        if ($this->agentQualifications->removeElement($agentQualification)) {
            // set the owning side to null (unless already changed)
            if ($agentQualification->getIdutilisateurAgent() === $this) {
                $agentQualification->setIdutilisateurAgent(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|AgentRestriction[]
     */
    public function getAgentRestrictions(): Collection
    {
        return $this->agentRestrictions;
    }

    public function addAgentRestriction(AgentRestriction $agentRestriction): self
    {
        if (!$this->agentRestrictions->contains($agentRestriction)) {
            $this->agentRestrictions[] = $agentRestriction;
            $agentRestriction->setUtilisateurAgent($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->getUtilisateurAgent() === $this) {
                $agentRestriction->setUtilisateurAgent(null);
            }
        }

        return $this;
    }

    /**
     * @ORM\PrePersist
     */
    public function onPrePersist(LifecycleEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();
        $entity->setDroits($entity->getRole()->getDroits());
        $entity->setInitiales(ucfirst(substr($entity->getPrenom(),0,1).substr(ucfirst($entity->getNom()),0,1)));
        $entity->setLogin(Functions::escapeString($entity->getPrenom()) . '.' . Functions::escapeString($entity->getNom()));
    }

    /**
     * @ORM\PreUpdate
     */
    public function onPreUpdate(LifecycleEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $uow = $entityManager->getUnitOfWork();
        $entity = $eventArgs->getEntity();

        // Vérifier si l'entité est en attente de mise à jour
        if ($uow->isScheduledForUpdate($entity)) {
            // Obtenir les changements prévus pour l'entité
            $changeSet = $uow->getEntityChangeSet($entity);
            // Si on a eu un changement de prénom ou de nom
            if (isset($changeSet['prenom']) || isset($changeSet['nom'])) {
                $entity->setLogin(Functions::escapeString($entity->getPrenom()) . '.' . Functions::escapeString($entity->getNom()));
                // Faites quelque chose avec $ancienneValeur
            }
        }
    }

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

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

        return $this;
    }


    public function getAppareils()
    {
        return $this->appareils;
    }

    public function setAppareils($appareils): self
    {
        $this->appareils = $appareils;

        return $this;
    }
    /**
     * @return Collection|AgentAppareil[]
     */
    public function getAgentAppareils(): Collection
    {
        return $this->agentAppareils;
    }

    public function addAgentAppareil(AgentAppareil $agentAppareil): self
    {
        if (!$this->agentAppareils->contains($agentAppareil)) {
            $this->agentAppareils[] = $agentAppareil;
            $agentAppareil->setUtilisateurAgent($this);
        }

        return $this;
    }

    public function removeAgentAppareil(AgentAppareil $agentAppareil): self
    {
        if ($this->agentAppareils->removeElement($agentAppareil)) {
            // set the owning side to null (unless already changed)
            if ($agentAppareil->getUtilisateurAgent() === $this) {
                $agentAppareil->setUtilisateurAgent(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, SectorisationVersion>
     * @Ignore()
     */
    public function getSectorisationVersions(): Collection
    {
        return $this->sectorisationVersions;
    }

    public function addSectorisationVersion(SectorisationVersion $sectorisationVersion): self
    {
        if (!$this->sectorisationVersions->contains($sectorisationVersion)) {
            $this->sectorisationVersions[] = $sectorisationVersion;
            $sectorisationVersion->setUtilisateur($this);
        }

        return $this;
    }

    public function removeSectorisationVersion(SectorisationVersion $sectorisationVersion): self
    {
        if ($this->sectorisationVersions->removeElement($sectorisationVersion)) {
            // set the owning side to null (unless already changed)
            if ($sectorisationVersion->getUtilisateur() === $this) {
                $sectorisationVersion->setUtilisateur(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, AgentSecteur>
     * @Ignore()
     */
    public function getAgentSecteurs(): Collection
    {
        return $this->agentSecteurs;
    }

    /**
     * @Ignore()
     */
    public function getSecteurPrincipal() {
        foreach($this->agentSecteurs as $agentSecteur) {
            if ($agentSecteur->getRangTri() == 1) return $agentSecteur->getSecteurVersion();
        }

        return null;
    }

    /**
     * @Ignore()
     */
    public function getSecteursSuppleant() {
        $secteurs = [];
        foreach($this->agentSecteurs as $agentSecteur) {
            if ($agentSecteur->getRangTri() != 1) $secteurs[] = $agentSecteur->getSecteurVersion();
        }
        return $secteurs;

    }


    public function addAgentSecteur(AgentSecteur $agentSecteur): self
    {
        if (!$this->agentSecteurs->contains($agentSecteur)) {
            $this->agentSecteurs[] = $agentSecteur;
            $agentSecteur->setUtilisateurAgent($this);
        }

        return $this;
    }

    public function removeAgentSecteur(AgentSecteur $agentSecteur): self
    {
        if ($this->agentSecteurs->removeElement($agentSecteur)) {
            // set the owning side to null (unless already changed)
            if ($agentSecteur->getUtilisateurAgent() === $this) {
                $agentSecteur->setUtilisateurAgent(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, AgentSecteur>
     * @Ignore()
     */
    public function getAgentGps(): Collection
    {
        return $this->agentGps;
    }

    public function addAgentGps(AgentGps $agentGps): self
    {
        if (!$this->agentGps->contains($agentGps)) {
            $this->agentGps[] = $agentGps;
            $agentGps->setUtilisateurAgent($this);
        }

        return $this;
    }

    public function removeAgentGps(AgentGps $agentGps): self
    {
        if ($this->agentGps->removeElement($agentGps)) {
            // set the owning side to null (unless already changed)
            if ($agentGps->getUtilisateurAgent() === $this) {
                $agentGps->setUtilisateurAgent(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Contrat>
     */
    public function getContratsAgentSouscripteur(): Collection
    {
        return $this->contrats_agent_souscripteur;
    }

    public function addContratsAgentSouscripteur(Contrat $contratsAgentSouscripteur): self
    {
        if (!$this->contrats_agent_souscripteur->contains($contratsAgentSouscripteur)) {
            $this->contrats_agent_souscripteur[] = $contratsAgentSouscripteur;
            $contratsAgentSouscripteur->setAgentSouscription($this);
        }

        return $this;
    }

    public function removeContratsAgentSouscripteur(Contrat $contratsAgentSouscripteur): self
    {
        if ($this->contrats_agent_souscripteur->removeElement($contratsAgentSouscripteur)) {
            // set the owning side to null (unless already changed)
            if ($contratsAgentSouscripteur->getAgentSouscription() === $this) {
                $contratsAgentSouscripteur->setAgentSouscription(null);
            }
        }

        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->setUtilisateurValidationTechnique($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->getUtilisateurValidationTechnique() === $this) {
                $intervention->setUtilisateurValidationTechnique(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->setUtilisateurAgent($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->getUtilisateurAgent() === $this) {
                $planning->setUtilisateurAgent(null);
            }
        }

        return $this;
    }

    public function getPhoto()
    {
        return  ($this->photo) ? stream_get_contents($this->photo) : '';
    }

    public function setPhoto($photo): self
    {
        $this->photo = $photo;

        return $this;
    }

    /**
     * @return Collection<int, LockEntites>
     */
    public function getLockEntites(): Collection
    {
        return $this->lockEntites;
    }

    public function addLockEntite(LockEntites $lockEntite): self
    {
        if (!$this->lockEntites->contains($lockEntite)) {
            $this->lockEntites[] = $lockEntite;
            $lockEntite->setUtilisateur($this);
        }

        return $this;
    }

    public function removeLockEntite(LockEntites $lockEntite): self
    {
        if ($this->lockEntites->removeElement($lockEntite)) {
            // set the owning side to null (unless already changed)
            if ($lockEntite->getUtilisateur() === $this) {
                $lockEntite->setUtilisateur(null);
            }
        }

        return $this;
    }

    public function getCodeAgent(): ?string
    {
        return $this->code_agent;
    }

    public function setCodeAgent(?string $code_agent): self
    {
        $this->code_agent = $code_agent;

        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->setUtilisateurModif($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->getUtilisateurModif() === $this) {
                $historiqueEquipementLocal->setUtilisateurModif(null);
            }
        }

        return $this;
    }

    public function isPlanning() {
        return (in_array($this->getRole()->getId(), [UtilisateurRole::ID_AGENT_PLANNING, UtilisateurRole::ID_REPONSABLE_AGENT_PLANNING]));
    }

    /**
     * @return Collection<int, InterventionStack>
     */
    public function getInterventionStacks(): Collection
    {
        return $this->interventionStacks;
    }

    public function addInterventionStack(InterventionStack $interventionStack): self
    {
        if (!$this->interventionStacks->contains($interventionStack)) {
            $this->interventionStacks[] = $interventionStack;
            $interventionStack->setAgent($this);
        }

        return $this;
    }

    public function removeInterventionStack(InterventionStack $interventionStack): self
    {
        if ($this->interventionStacks->removeElement($interventionStack)) {
            // set the owning side to null (unless already changed)
            if ($interventionStack->getAgent() === $this) {
                $interventionStack->setAgent(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Secteur>
     */
    public function getSecteurs(): Collection
    {
        return $this->secteurs;
    }

    public function addSecteur(Secteur $secteur): self
    {
        if (!$this->secteurs->contains($secteur)) {
            $this->secteurs[] = $secteur;
            $secteur->setUtilisateurPlanning($this);
        }

        return $this;
    }

    public function removeSecteur(Secteur $secteur): self
    {
        if ($this->secteurs->removeElement($secteur)) {
            // set the owning side to null (unless already changed)
            if ($secteur->getUtilisateurPlanning() === $this) {
                $secteur->setUtilisateurPlanning(null);
            }
        }

        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->setUtilisateur($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->getUtilisateur() === $this) {
                $planningHistoriqueModification->setUtilisateur(null);
            }
        }

        return $this;
    }
}
