<?php
declare(strict_types=1);

namespace App\Entity\Billing;

use App\Entity\Core\Tagg;
use App\Entity\Product\Intangible;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\Common\Collections\Collection;

/**
 * Enregistrement d'un produit à facturer par une Organization, un Access ou un EducationalProject
 * Classe de base de @see AccessIntangible, EducationalProjectIntangible
 */
#[ORM\Entity]
#[ORM\Table(name: 'BillingIntangible')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
#[ORM\DiscriminatorMap([
    'access' => 'AccessIntangible',
    'educationalproject' => 'EducationalProjectIntangible'
])]
abstract class AbstractBillingIntangible {
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    protected ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'accessIntangibles')]
    #[ORM\JoinColumn(nullable: false)]
    protected Intangible $intangible;

    #[ORM\ManyToMany(targetEntity: Tagg::class, inversedBy: 'billingIntangibles', cascade: ['persist'])]
    #[ORM\JoinTable(name: 'tag_billingIntangible')]
    #[ORM\JoinColumn(name: 'billingIntangible_id', referencedColumnName: 'id')]
    #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
    protected Collection $tags;

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

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

    public function getIntangible(): ?Intangible
    {
        return $this->intangible;
    }

    public function setIntangible(?Intangible $intangible): self
    {
        $this->intangible = $intangible;

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