<?php

namespace App\Entity;

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity=Target::class, inversedBy="normeActionCommunes")
     */
    private $target;

    /**
     * @ORM\ManyToOne(targetEntity=Commune::class, inversedBy="normeActionCommunes")
     */
    private $commune;

    /**
     * @ORM\OneToMany(targetEntity=ActivityNormeCommune::class, mappedBy="norme")
     */
    private $action;

    public function __construct()
    {
        $this->action = 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 getCommune(): ?Commune
    {
        return $this->commune;
    }

    public function setCommune(?Commune $commune): self
    {
        $this->commune = $commune;

        return $this;
    }

    /**
     * @return Collection<int, ActivityNormeCommune>
     */
    public function getAction(): Collection
    {
        return $this->action;
    }

    public function addAction(ActivityNormeCommune $action): self
    {
        if (!$this->action->contains($action)) {
            $this->action[] = $action;
            $action->setNorme($this);
        }

        return $this;
    }

    public function removeAction(ActivityNormeCommune $action): self
    {
        if ($this->action->removeElement($action)) {
            // set the owning side to null (unless already changed)
            if ($action->getNorme() === $this) {
                $action->setNorme(null);
            }
        }

        return $this;
    }
}
