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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Goal", inversedBy="targets")
     * @ORM\JoinColumn(nullable=false)
     */
    private $goal;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Indicator", mappedBy="target", orphanRemoval=true)
     */
    private $indicators;

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

    /**
     * @ORM\Column(type="boolean")
     */
    private $pertinant=true;

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

    public function __construct()
    {
        $this->indicators = new ArrayCollection();
        $this->normeActionCommunes = new ArrayCollection();
    }

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

    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 getGoal(): ?Goal
    {
        return $this->goal;
    }

    public function setGoal(?Goal $goal): self
    {
        $this->goal = $goal;

        return $this;
    }

    /**
     * @return Collection|Indicator[]
     */
    public function getIndicators(): Collection
    {
        return $this->indicators;
    }

    public function addIndicator(Indicator $indicator): self
    {
        if (!$this->indicators->contains($indicator)) {
            $this->indicators[] = $indicator;
            $indicator->setTarget($this);
        }

        return $this;
    }

    public function removeIndicator(Indicator $indicator): self
    {
        if ($this->indicators->contains($indicator)) {
            $this->indicators->removeElement($indicator);
            // set the owning side to null (unless already changed)
            if ($indicator->getTarget() === $this) {
                $indicator->setTarget(null);
            }
        }

        return $this;
    }

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

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

        return $this;
    }

    public function getPertinant(): ?bool
    {
        return $this->pertinant;
    }

    public function setPertinant(bool $pertinant): self
    {
        $this->pertinant = $pertinant;

        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->setTarget($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->getTarget() === $this) {
                $normeActionCommune->setTarget(null);
            }
        }

        return $this;
    }
}
