<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\CommuneRepository")
 */
class Commune
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Department", inversedBy="communes")
     * @ORM\JoinColumn(nullable=false)
     */
    private $department;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Programm", mappedBy="commune", orphanRemoval=true, fetch="EAGER")
     */
    private $programms;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Arrondissement", mappedBy="commune", orphanRemoval=true, fetch="EAGER")
     */
    private $arrondissements;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Pole", inversedBy="communes")
     * @ORM\JoinColumn(nullable=false)
     */
    private $pole;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Zone", inversedBy="communes")
     * @ORM\JoinColumn(nullable=false)
     */
    private $zone;

    /**
     * @ORM\OneToMany(targetEntity=User::class, mappedBy="commune")
     */
    private $users;

    /**
     * @var array
     * @ORM\Column(type="json", nullable=true)
     */
    private $cibles;

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

    /**
     * @ORM\OneToMany(targetEntity=NormeActionCommune::class, mappedBy="commune")
     */
    private $normeActionCommunes;

    /**
     * @ORM\OneToMany(targetEntity=ActivityNormeCommune::class, mappedBy="commune")
     */
    private $activityNormeCommunes;

    /**
     * @ORM\OneToMany(targetEntity=ValeurSousIndicateur::class, mappedBy="commune")
     */
    private $valeurSousIndicateurs;

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

    public function __construct()
    {
        $this->users = new ArrayCollection();
        $this->cibles = array();
        $this->normeActionCommunes = new ArrayCollection();
        $this->activityNormeCommunes = new ArrayCollection();
        $this->valeurSousIndicateurs = new ArrayCollection();
    }

    public function __toString()
    {
        return $this->getName();
    }

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getDepartment(): ?Department
    {
        return $this->department;
    }

    public function setDepartment(?Department $department): self
    {
        $this->department = $department;

        return $this;
    }

    public function getPole(): ?Pole
    {
        return $this->pole;
    }

    public function setPole(?Pole $pole): self
    {
        $this->pole = $pole;

        return $this;
    }

    public function getZone(): ?Zone
    {
        return $this->zone;
    }

    public function setZone(?Zone $zone): self
    {
        $this->zone = $zone;

        return $this;
    }

    public function getCibles() : ?array
    {
        return $this->cibles;
    }

    public function setCibles($cibles): self
    {
        $this->cibles = $cibles;

        return $this;
    }

    /**
     * @return Collection|User[]
     */
    public function getUsers(): Collection
    {
        return $this->users;
    }

    public function addUser(User $user): self
    {
        if (!$this->users->contains($user)) {
            $this->users[] = $user;
            $user->setCommune($this);
        }

        return $this;
    }

    public function removeUser(User $user): self
    {
        if ($this->users->removeElement($user)) {
            // set the owning side to null (unless already changed)
            if ($user->getCommune() === $this) {
                $user->setCommune(null);
            }
        }

        return $this;
    }

    public function getCoordonnee(): ?string
    {
        return $this->coordonnee;
    }

    public function setCoordonnee(?string $coordonnee): self
    {
        $this->coordonnee = $coordonnee;

        return $this;
    }

    /**
     * @return Collection|Programm[]
     */
    public function getProgramms(): Collection
    {
        return $this->programms;
    }

    public function addProgramm(Programm $programm): self
    {
        if (!$this->programms->contains($programm)) {
            $this->programms[] = $programm;
            $programm->setCommune($this);
        }

        return $this;
    }

    public function removeProgramm(Programm $programm): self
    {
        if ($this->programms->contains($programm)) {
            $this->programms->removeElement($programm);
            // set the owning side to null (unless already changed)
            if ($programm->setCommune() === $this) {
                $programm->setCommune(null);
            }
        }

        return $this;
    }



    /**
     * @return Collection|Arrondissement[]
     */
    public function getArrondissements(): Collection
    {
        return $this->arrondissements;
    }

    public function addArrondissement(Arrondissement $arrondissement): self
    {
        if (!$this->arrondissements->contains($arrondissement)) {
            $this->arrondissements[] = $arrondissement;
            $arrondissement->setCommune($this);
        }

        return $this;
    }



    /**
     * @return Collection<int, NormeActionCommune>
     */
    public function getNormeActionCommunes(): Collection
    {
        return $this->normeActionCommunes;
    }

    public function addNormeActionCommune(NormeActionCommune $normeActionCommune): self
    {
        if (!$this->normeActionCommunes->contains($normeActionCommune)) {
            $this->normeActionCommunes[] = $normeActionCommune;
            $normeActionCommune->setCommune($this);
        }

        return $this;
    }

    public function removeNormeActionCommune(NormeActionCommune $normeActionCommune): self
    {
        if ($this->normeActionCommunes->removeElement($normeActionCommune)) {
            // set the owning side to null (unless already changed)
            if ($normeActionCommune->getCommune() === $this) {
                $normeActionCommune->setCommune(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, ActivityNormeCommune>
     */
    public function getActivityNormeCommunes(): Collection
    {
        return $this->activityNormeCommunes;
    }

    public function addActivityNormeCommune(ActivityNormeCommune $activityNormeCommune): self
    {
        if (!$this->activityNormeCommunes->contains($activityNormeCommune)) {
            $this->activityNormeCommunes[] = $activityNormeCommune;
            $activityNormeCommune->setCommune($this);
        }

        return $this;
    }

    public function removeActivityNormeCommune(ActivityNormeCommune $activityNormeCommune): self
    {
        if ($this->activityNormeCommunes->removeElement($activityNormeCommune)) {
            // set the owning side to null (unless already changed)
            if ($activityNormeCommune->getCommune() === $this) {
                $activityNormeCommune->setCommune(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, ValeurSousIndicateur>
     */
    public function getValeurSousIndicateurs(): Collection
    {
        return $this->valeurSousIndicateurs;
    }

    public function addValeurSousIndicateur(ValeurSousIndicateur $valeurSousIndicateur): self
    {
        if (!$this->valeurSousIndicateurs->contains($valeurSousIndicateur)) {
            $this->valeurSousIndicateurs[] = $valeurSousIndicateur;
            $valeurSousIndicateur->setCommune($this);
        }

        return $this;
    }

    public function removeValeurSousIndicateur(ValeurSousIndicateur $valeurSousIndicateur): self
    {
        if ($this->valeurSousIndicateurs->removeElement($valeurSousIndicateur)) {
            // set the owning side to null (unless already changed)
            if ($valeurSousIndicateur->getCommune() === $this) {
                $valeurSousIndicateur->setCommune(null);
            }
        }

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;

        return $this;
    }

}
