<?php

declare(strict_types=1);

namespace App\Entity\Place;

use App\Entity\Core\AddressPostal;
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 Place, et supprimer l'attribut discr.
 *
 * Classe de base de @see Place, PlaceSystem
 */
#[ORM\Entity]
#[ORM\Table(name: 'Place')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
#[ORM\DiscriminatorMap(
    [
        'place_system' => PlaceSystem::class,
        'place' => Place::class,
    ]
)]
abstract class AbstractPlace
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'places')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?AddressPostal $addressPostal;

    /** @var Collection<int, Tagg> */
    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'places', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_place')]
    #[ORM\JoinColumn(name: 'place_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    private Collection $tags;

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

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getAddressPostal(): ?AddressPostal
    {
        return $this->addressPostal;
    }

    public function setAddressPostal(?AddressPostal $addressPostal): self
    {
        $this->addressPostal = $addressPostal;

        return $this;
    }

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