<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Ferienpass\CoreBundle\Entity\Participant\ParticipantInterface;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity]
#[ORM\Table(name: 'participant_duplicate')]
#[ORM\UniqueConstraint(columns: ['participant_id', 'duplicate_id'])]
class ParticipantDuplicate implements TenantAwareInterface
{
    use TenantAwareTrait;

    final public const string TYPE_TOLERATED = 'tolerated';
    final public const string TYPE_IGNORED = 'ignored';

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    private ?int $id = null;

    #[ORM\Column(type: UuidType::NAME)]
    private Uuid $uuid;

    #[ORM\ManyToOne(targetEntity: ParticipantInterface::class, inversedBy: 'duplicates')]
    #[ORM\JoinColumn(name: 'participant_id', nullable: false, onDelete: 'CASCADE')]
    private ParticipantInterface $participant;

    #[ORM\ManyToOne(targetEntity: ParticipantInterface::class)]
    #[ORM\JoinColumn(name: 'duplicate_id', nullable: false, onDelete: 'CASCADE')]
    private ParticipantInterface $duplicate;

    #[ORM\Column(type: 'string', length: 20)]
    private string $type;

    public function __construct(ParticipantInterface $participant, ParticipantInterface $duplicate, string $type)
    {
        $this->uuid = Uuid::v7();
        $this->participant = $participant;
        $this->duplicate = $duplicate;
        $this->type = $type;
    }

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

    public function getUuid(): Uuid
    {
        return $this->uuid;
    }

    public function getParticipant(): ParticipantInterface
    {
        return $this->participant;
    }

    public function getDuplicate(): ParticipantInterface
    {
        return $this->duplicate;
    }

    public function getType(): string
    {
        return $this->type;
    }

    public function setType(string $type): void
    {
        $this->type = $type;
    }
}
