<?php

namespace App\Entity;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity=Modalite::class, mappedBy="desagregation")
     */
    private $modalites;

    public function __construct()
    {
        $this->modalites = 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;
    }

    /**
     * @return Collection<int, Modalite>
     */
    public function getModalites(): Collection
    {
        return $this->modalites;
    }

    public function addModalite(Modalite $modalite): self
    {
        if (!$this->modalites->contains($modalite)) {
            $this->modalites[] = $modalite;
            $modalite->setDesagregation($this);
        }

        return $this;
    }

    public function removeModalite(Modalite $modalite): self
    {
        if ($this->modalites->removeElement($modalite)) {
            // set the owning side to null (unless already changed)
            if ($modalite->getDesagregation() === $this) {
                $modalite->setDesagregation(null);
            }
        }

        return $this;
    }
}
