<?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\IndicatorRepository")
 */
class Indicator
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

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

    /**
     * @ORM\Column(type="text")
     */
    private $name;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Target", inversedBy="indicators")
     * @ORM\JoinColumn(nullable=false)
     */
    private $target;

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

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

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Indice", mappedBy="indicator", cascade={"persist"})
     */
    private $indices;

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

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

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

    /**
     * @ORM\Column(type="boolean")
     */
    protected $communal = false;

    /**
     * @ORM\ManyToOne(targetEntity=Ministry::class, inversedBy="indicators")
     */
    private $ministere;

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

    /**
     * @ORM\OneToMany(targetEntity=IndiceCommune::class, mappedBy="indicator")
     */
    private $indiceCommunes;

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

    /**
     * @ORM\OneToMany(targetEntity=SousIndicateur::class, mappedBy="indicateur")
     */
    private $sousIndicateurs;

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

    /**
     * @ORM\OneToMany(targetEntity=Cible2063::class, mappedBy="domaine")
     */
    private $cibles;

    /**
     * @ORM\OneToMany(targetEntity=Indicateur2063::class, mappedBy="indicateur2030")
     */
    private $indicateurs2063;

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

    public function __construct()
    {
        $this->indices = new ArrayCollection();
        $this->desagregations = array();
        $this->indiceCommunes = new ArrayCollection();
        $this->sousIndicateurs = new ArrayCollection();
        $this->cibles = new ArrayCollection();
        $this->indicateurs2063 = new ArrayCollection();
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

    public function getTarget(): ?Target
    {
        return $this->target;
    }

    public function setTarget(?Target $target): self
    {
        $this->target = $target;

        return $this;
    }

    public function getMinValue(): ?float
    {
        return $this->minValue;
    }

    public function setMinValue(?float $minValue): self
    {
        $this->minValue = $minValue;

        return $this;
    }

    public function getMaxValue(): ?float
    {
        return $this->maxValue;
    }

    public function setMaxValue(?float $maxValue): self
    {
        $this->maxValue = $maxValue;

        return $this;
    }

    public function isCommunal()
    {
        return $this->communal;
    }

    public function setCommunal($boolean)
    {
        $this->communal = (bool) $boolean;

        return $this;
    }

    /**
     * @return Collection|Indice[]
     */
    public function getIndices(): Collection
    {
        return $this->indices;
    }

    public function addIndice(Indice $indice): self
    {
        if (!$this->indices->contains($indice)) {
            $this->indices[] = $indice;
            $indice->setActivity($this);
        }

        return $this;
    }

    public function removeIndice(Indice $indice): self
    {
        if ($this->indices->contains($indice)) {
            $this->indices->removeElement($indice);
            // set the owning side to null (unless already changed)
            if ($indice->getActivity() === $this) {
                $indice->setActivity(null);
            }
        }

        return $this;
    }

    public function getRefValue(): ?float
    {
        return $this->refValue;
    }

    public function setRefValue(?float $refValue): self
    {
        $this->refValue = $refValue;

        return $this;
    }

    public function getRefYear(): ?int
    {
        return $this->refYear;
    }

    public function setRefYear(?int $refYear): self
    {
        $this->refYear = $refYear;

        return $this;
    }

    public function getUnity(): ?string
    {
        return $this->unity;
    }

    public function setUnity(?string $unity): self
    {
        $this->unity = $unity;

        return $this;
    }

    public function getMinistere(): ?Ministry
    {
        return $this->ministere;
    }

    public function setMinistere(?Ministry $ministere): self
    {
        $this->ministere = $ministere;

        return $this;
    }

    public function getDesagregations() : ?array
    {
        return $this->desagregations;
    }

    public function setDesagregations($desagregations): self
    {
        $this->desagregations = $desagregations;

        return $this;
    }

    /**
     * @return Collection|IndiceCommune[]
     */
    public function getIndiceCommunes(): Collection
    {
        return $this->indiceCommunes;
    }

    public function addIndiceCommune(IndiceCommune $indiceCommune): self
    {
        if (!$this->indiceCommunes->contains($indiceCommune)) {
            $this->indiceCommunes[] = $indiceCommune;
            $indiceCommune->setIndicator($this);
        }

        return $this;
    }

    public function removeIndiceCommune(IndiceCommune $indiceCommune): self
    {
        if ($this->indiceCommunes->removeElement($indiceCommune)) {
            // set the owning side to null (unless already changed)
            if ($indiceCommune->getIndicator() === $this) {
                $indiceCommune->setIndicator(null);
            }
        }

        return $this;
    }

    public function getInstad(): ?bool
    {
        return $this->instad;
    }

    public function setInstad(?bool $instad): self
    {
        $this->instad = $instad;

        return $this;
    }

    /**
     * @return Collection<int, SousIndicateur>
     */
    public function getSousIndicateurs(): Collection
    {
        return $this->sousIndicateurs;
    }

    public function addSousIndicateur(SousIndicateur $sousIndicateur): self
    {
        if (!$this->sousIndicateurs->contains($sousIndicateur)) {
            $this->sousIndicateurs[] = $sousIndicateur;
            $sousIndicateur->setIndicateur($this);
        }

        return $this;
    }

    public function removeSousIndicateur(SousIndicateur $sousIndicateur): self
    {
        if ($this->sousIndicateurs->removeElement($sousIndicateur)) {
            // set the owning side to null (unless already changed)
            if ($sousIndicateur->getIndicateur() === $this) {
                $sousIndicateur->setIndicateur(null);
            }
        }

        return $this;
    }

    public function getOrdre(): ?int
    {
        return $this->ordre;
    }

    public function setOrdre(?int $ordre): self
    {
        $this->ordre = $ordre;

        return $this;
    }

    /**
     * @return Collection<int, Cible2063>
     */
    public function getCibles(): Collection
    {
        return $this->cibles;
    }

    public function addCible(Cible2063 $cible): self
    {
        if (!$this->cibles->contains($cible)) {
            $this->cibles[] = $cible;
            $cible->setDomaine($this);
        }

        return $this;
    }

    public function removeCible(Cible2063 $cible): self
    {
        if ($this->cibles->removeElement($cible)) {
            // set the owning side to null (unless already changed)
            if ($cible->getDomaine() === $this) {
                $cible->setDomaine(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Indicateur2063>
     */
    public function getIndicateurs2063(): Collection
    {
        return $this->indicateurs2063;
    }

    public function addIndicateurs2063(Indicateur2063 $indicateurs2063): self
    {
        if (!$this->indicateurs2063->contains($indicateurs2063)) {
            $this->indicateurs2063[] = $indicateurs2063;
            $indicateurs2063->setIndicateur2030($this);
        }

        return $this;
    }

    public function removeIndicateurs2063(Indicateur2063 $indicateurs2063): self
    {
        if ($this->indicateurs2063->removeElement($indicateurs2063)) {
            // set the owning side to null (unless already changed)
            if ($indicateurs2063->getIndicateur2030() === $this) {
                $indicateurs2063->setIndicateur2030(null);
            }
        }

        return $this;
    }

}
