<?php
declare(strict_types=1);

namespace App\Entity\Product;

use App\Entity\Access\Access;
use App\Entity\Core\AbstractRepair;
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;

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

    #[ORM\ManyToOne(inversedBy: 'equipmentRepairProviders')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private Access $provider;

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

    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'equipmentRepairs', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_repair')]
    #[ORM\JoinColumn(name: 'repair_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 getProvider(): ?Access
    {
        return $this->provider;
    }

    public function setProvider(?Access $provider): self
    {
        $this->provider = $provider;

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