<?php

namespace App\Entity;

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

/**
 * @ORM\Table(schema="sav")
 * @ORM\Entity(repositoryClass=UtilisateurRoleRepository::class)
 */
class UtilisateurRole
{
    const ID_AGENT = 5;
    const ID_RESPONSABLE_SECTEUR = 4;
    const ID_AGENT_PLANNING = 7;
    const ID_RENSEIGNEMENT_TECHNIQUE = 10;
    const ID_REPONSABLE_AGENT_PLANNING  = 6;
    const ID_ROLE_RESPONSABLE_TECHNIQUE = 12;


    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    private $libelle;

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

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

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

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

    public function __construct()
    {
        $this->utilisateurs = new ArrayCollection();
        $this->utilisateurFiltres = new ArrayCollection();
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * @Ignore()
     * @return Collection|Utilisateur[]
     */
    public function getUtilisateurs(): Collection
    {
        return $this->utilisateurs;
    }

    public function addUtilisateur(Utilisateur $utilisateur): self
    {
        if (!$this->utilisateurs->contains($utilisateur)) {
            $this->utilisateurs[] = $utilisateur;
            $utilisateur->setRole($this);
        }

        return $this;
    }

    public function removeUtilisateur(Utilisateur $utilisateur): self
    {
        if ($this->utilisateurs->removeElement($utilisateur)) {
            // set the owning side to null (unless already changed)
            if ($utilisateur->getRole() === $this) {
                $utilisateur->setRole(null);
            }
        }

        return $this;
    }

    public function isAgent () {
        return ($this->getId() == self::ID_AGENT);
    }

    public function getEstResponsable(): ?bool
    {
        return $this->est_responsable;
    }

    public function setEstResponsable(?bool $est_responsable): self
    {
        $this->est_responsable = $est_responsable;

        return $this;
    }
}
