<?php

declare(strict_types=1);

namespace App\Module\Mail\Domain\Entity;

use App\Module\Mail\Infrastructure\Doctrine\DoctrineTaskMailLinkRepository;
use App\Shared\Domain\Contract\TaskInterface;
use App\Shared\Domain\Contract\UserInterface;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: DoctrineTaskMailLinkRepository::class)]
#[ORM\Table(name: 'task_mail_link')]
#[ORM\UniqueConstraint(name: 'uq_task_mail_link', columns: ['task_id', 'mail_message_id'])]
class TaskMailLink
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: TaskInterface::class)]
    #[ORM\JoinColumn(name: 'task_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private TaskInterface $task;

    #[ORM\ManyToOne(targetEntity: MailMessage::class)]
    #[ORM\JoinColumn(name: 'mail_message_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private MailMessage $mailMessage;

    #[ORM\Column(type: 'datetimetz_immutable')]
    private DateTimeImmutable $linkedAt;

    #[ORM\ManyToOne(targetEntity: UserInterface::class)]
    #[ORM\JoinColumn(name: 'linked_by_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?UserInterface $linkedBy = null;

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

    public function getTask(): TaskInterface
    {
        return $this->task;
    }

    public function setTask(TaskInterface $task): static
    {
        $this->task = $task;

        return $this;
    }

    public function getMailMessage(): MailMessage
    {
        return $this->mailMessage;
    }

    public function setMailMessage(MailMessage $mailMessage): static
    {
        $this->mailMessage = $mailMessage;

        return $this;
    }

    public function getLinkedAt(): DateTimeImmutable
    {
        return $this->linkedAt;
    }

    public function setLinkedAt(DateTimeImmutable $linkedAt): static
    {
        $this->linkedAt = $linkedAt;

        return $this;
    }

    public function getLinkedBy(): ?UserInterface
    {
        return $this->linkedBy;
    }

    public function setLinkedBy(?UserInterface $linkedBy): static
    {
        $this->linkedBy = $linkedBy;

        return $this;
    }
}
