<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'document_tag')]
#[ORM\Index(name: 'idx_document_tag_tag_id', columns: ['tag_id'])]
class DocumentTag
{
    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Document::class, inversedBy: 'documentTags')]
    #[ORM\JoinColumn(name: 'document_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private Document $document;

    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Tag::class)]
    #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private Tag $tag;

    public function __construct(Document $document, Tag $tag)
    {
        $this->setDocument($document);
        $this->setTag($tag);
    }

    public function getDocument(): Document
    {
        return $this->document;
    }

    public function getTag(): Tag
    {
        return $this->tag;
    }

    public function isSameRelation(Document $document, Tag $tag): bool
    {
        return $this->document->getId()->equals($document->getId())
            && $this->tag->getId()->equals($tag->getId());
    }

    private function setDocument(Document $document): void
    {
        $this->document = $document;
    }

    private function setTag(Tag $tag): void
    {
        $this->tag = $tag;
    }
}