<?php

namespace App\Entity;

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

/**
 * @ORM\Entity(repositoryClass=AgenceRepository::class)
 * @ORM\Table(schema="sav")
 */
class Agence
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"site_list"})
     */
    private $id;

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

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

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

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

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

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

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

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

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

    /**
     * @ORM\OneToMany(targetEntity=Facture::class, mappedBy="agence")
     * @Ignore()
     */
    private $factures;

    /**
     * @ORM\OneToMany(targetEntity=PorteOuverte::class, mappedBy="agence")
     * @Ignore()
     */
    private $porteOuvertes;

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

    /**
     * @ORM\OneToMany(targetEntity=AgenceAdresse::class, mappedBy="agence")
     */
    private $agenceAdresses;

    public function __construct()
    {
        $this->utilisateurs = new ArrayCollection();
        $this->factures = new ArrayCollection();
        $this->porteOuvertes = new ArrayCollection();
        $this->evenements = new ArrayCollection();
        $this->agenceAdresses = new ArrayCollection();
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

    public function getRaisonSociale(): ?string
    {
        return $this->raison_sociale;
    }

    public function setRaisonSociale(?string $raison_sociale): self
    {
        $this->raison_sociale = $raison_sociale;

        return $this;
    }

    public function getTypeSociete(): ?string
    {
        return $this->type_societe;
    }

    public function setTypeSociete(?string $type_societe): self
    {
        $this->type_societe = $type_societe;

        return $this;
    }

    public function getBanque(): ?string
    {
        return $this->banque;
    }

    public function setBanque(?string $banque): self
    {
        $this->banque = $banque;

        return $this;
    }

    public function getNumTel(): ?string
    {
        return $this->num_tel;
    }

    public function setNumTel(?string $num_tel): self
    {
        $this->num_tel = $num_tel;

        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;
    }

    public function getPrivilege(): ?bool
    {
        return $this->privilege;
    }

    public function setPrivilege(?bool $privilege): self
    {
        $this->privilege = $privilege;

        return $this;
    }

    /**
     * @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->setAgence($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->getAgence() === $this) {
                $utilisateur->setAgence(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->setAgence($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->getAgence() === $this) {
                $facture->setAgence(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, PorteOuverte>
     */
    public function getPorteOuvertes(): Collection
    {
        return $this->porteOuvertes;
    }

    public function addPorteOuverte(PorteOuverte $porteOuverte): self
    {
        if (!$this->porteOuvertes->contains($porteOuverte)) {
            $this->porteOuvertes[] = $porteOuverte;
            $porteOuverte->setAgence($this);
        }

        return $this;
    }

    public function removePorteOuverte(PorteOuverte $porteOuverte): self
    {
        if ($this->porteOuvertes->removeElement($porteOuverte)) {
            // set the owning side to null (unless already changed)
            if ($porteOuverte->getAgence() === $this) {
                $porteOuverte->setAgence(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Evenement>
     */
    public function getEvenements(): Collection
    {
        return $this->evenements;
    }

    public function addEvenement(Evenement $evenement): self
    {
        if (!$this->evenements->contains($evenement)) {
            $this->evenements[] = $evenement;
            $evenement->setAgence($this);
        }

        return $this;
    }

    public function removeEvenement(Evenement $evenement): self
    {
        if ($this->evenements->removeElement($evenement)) {
            // set the owning side to null (unless already changed)
            if ($evenement->getAgence() === $this) {
                $evenement->setAgence(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, AgenceAdresse>
     */
    public function getAgenceAdresses(): Collection
    {
        return $this->agenceAdresses;
    }

    public function addAgenceAdresse(AgenceAdresse $agenceAdresse): self
    {
        if (!$this->agenceAdresses->contains($agenceAdresse)) {
            $this->agenceAdresses[] = $agenceAdresse;
            $agenceAdresse->setAgence($this);
        }

        return $this;
    }

    public function removeAgenceAdresse(AgenceAdresse $agenceAdresse): self
    {
        if ($this->agenceAdresses->removeElement($agenceAdresse)) {
            // set the owning side to null (unless already changed)
            if ($agenceAdresse->getAgence() === $this) {
                $agenceAdresse->setAgence(null);
            }
        }

        return $this;
    }

    /**
     * @SerializedName("adresse")
     * @Groups({"api"})
     */
    public function getAdresseActive(): ?Adresse
    {
        foreach ($this->agenceAdresses as $agenceAdresse) {
            if ($agenceAdresse->getActif()) {
                $adresse = $agenceAdresse->getAdresse();
                return $adresse;
            }
        }

        return null;
    }
}
