<?php
declare(strict_types=1);

namespace App\Entity\Product;

use App\Entity\Core\Tagg;
//use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Core\AbstractControl;

/**
 * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table EquipmentControl, et supprimer l'attribut discr.
 *
 * Classe ... qui ...
 */
//#[Auditable]
#[ORM\Entity]
#[ORM\Table(name: 'Control')]
class EquipmentControl extends AbstractControl
{
    #[ORM\Column(length: 255, nullable: false)]
    private string $discr = 'equipment';

    #[ORM\ManyToOne(inversedBy: 'equipmentControl')]
    private Equipment $equipment;

    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'equipmentControls', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_control')]
    #[ORM\JoinColumn(name: 'control_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    private Collection $tags;

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

    public function getDiscr(): ?string
    {
        return $this->discr;
    }

    public function setDiscr(string $discr): self
    {
        $this->discr = $discr;

        return $this;
    }

    public function getEquipment(): ?Equipment
    {
        return $this->equipment;
    }

    public function setEquipment(?Equipment $equipment): self
    {
        $this->equipment = $equipment;

        return $this;
    }

    /**
     * @return Collection<int, Tagg>
     */
    public function getTags(): Collection
    {
        return $this->tags;
    }

    public function addTag(Tagg $tag): self
    {
        if (!$this->tags->contains($tag)) {
            $this->tags[] = $tag;
        }

        return $this;
    }

    public function removeTag(Tagg $tag): self
    {
        $this->tags->removeElement($tag);

        return $this;
    }
}