<?php

namespace App\Entity;

use App\Repository\TerritoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=TerritoryRepository::class)
 */
class Territory
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

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

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

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

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

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