<?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\Offer\OfferInterface;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

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

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

    #[ORM\ManyToOne(targetEntity: OfferInterface::class, inversedBy: 'attachments')]
    #[ORM\JoinColumn(name: 'offer_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
    private OfferInterface $offer;

    #[ORM\ManyToOne(targetEntity: DbafsAttachment::class, inversedBy: 'offers')]
    #[ORM\JoinColumn(name: 'attachment_id', referencedColumnName: 'uuid', onDelete: 'CASCADE')]
    private DbafsAttachment $attachment;

    #[ORM\Column(type: 'boolean', nullable: false)]
    private bool $agreementLetter = false;

    #[ORM\Column(type: 'integer', options: ['unsigned' => true, 'default' => 0])]
    private int $sorting = 0;

    public function __construct(?OfferInterface $offer = null, ?DbafsAttachment $attachment = null)
    {
        $this->uuid = Uuid::v7();

        if ($offer instanceof OfferInterface) {
            $this->offer = $offer;
        }

        if ($attachment instanceof DbafsAttachment) {
            $this->attachment = $attachment;
        }
    }

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

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

    public function setOffer(OfferInterface $offer): void
    {
        $this->offer = $offer;
    }

    public function setAttachment(DbafsAttachment $attachment): void
    {
        $this->attachment = $attachment;
    }

    public function getOffer(): OfferInterface
    {
        return $this->offer;
    }

    public function getAttachment(): DbafsAttachment
    {
        return $this->attachment;
    }

    public function isAgreementLetter(): bool
    {
        return $this->agreementLetter;
    }

    public function setAgreementLetter(bool $agreementLetter): void
    {
        $this->agreementLetter = $agreementLetter;
    }

    public function getSorting(): int
    {
        return $this->sorting;
    }

    public function setSorting(int $sorting): void
    {
        $this->sorting = $sorting;
    }
}
