<?php

namespace App\Entity;

use App\Repository\TerritoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;

/**
 * @ORM\Entity(repositoryClass=TerritoryRepository::class)
 */
class Territory implements EntityInterface, DevAliasInterface
{
    use DevAliasTrait;

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

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

    /**
     * @ORM\OneToMany(targetEntity=IndividualData::class, mappedBy="territory")
     */
    private $individualData;

    /**
     * @ORM\OneToMany(targetEntity=CollectifData::class, mappedBy="territory")
     */
    private $collectifData;

    public function __construct()
    {
        $this->collectifData = new ArrayCollection();
        $this->individualData = new ArrayCollection();
    }

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

    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 getIndividualData(): ?IndividualData
    {
        return $this->individualData;
    }

    public function setIndividualData(?IndividualData $individualData): self
    {
        $this->individualData = $individualData;

        return $this;
    }

    /**
     * @return Collection|CollectifData[]
     */
    public function getCollectifData(): Collection
    {
        return $this->collectifData;
    }

    public function addCollectifData(CollectifData $collectifData): self
    {
        if (!$this->collectifData->contains($collectifData)) {
            $this->collectifData[] = $collectifData;
            $collectifData->setTerritory($this);
        }

        return $this;
    }

    public function removeCollectifData(CollectifData $collectifData): self
    {
        if ($this->collectifData->removeElement($collectifData)) {
            // set the owning side to null (unless already changed)
            if ($collectifData->getTerritory() === $this) {
                $collectifData->setTerritory(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Territory[]
     */
    public function getTerritory(): Collection
    {
        return $this->territory;
    }

    public function addTerritory(Territory $territory): self
    {
        if (!$this->territory->contains($territory)) {
            $this->territory[] = $territory;
            $territory->setIndividualData($this);
        }

        return $this;
    }

    public function removeTerritory(Territory $territory): self
    {
        if ($this->territory->removeElement($territory)) {
            // set the owning side to null (unless already changed)
            if ($territory->getIndividualData() === $this) {
                $territory->setIndividualData(null);
            }
        }

        return $this;
    }
}
