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

/**
 * A single offer on a {@see Wishlist}. The FK to the offer (onDelete cascade)
 * keeps the list referentially clean — when an offer is removed the item goes
 * with it. {@see $createdAt} enables per-item retention.
 */
#[ORM\Entity]
#[ORM\UniqueConstraint(name: 'wishlist_offer', columns: ['wishlist_id', 'offer_id'])]
class WishlistItem
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    private Uuid $id;

    #[ORM\Column(type: 'datetime_immutable', options: ['default' => 'CURRENT_TIMESTAMP'])]
    private \DateTimeImmutable $createdAt;

    public function __construct(
        #[ORM\ManyToOne(targetEntity: Wishlist::class, inversedBy: 'items')]
        #[ORM\JoinColumn(name: 'wishlist_id', referencedColumnName: 'id', nullable: false, onDelete: 'cascade')]
        private Wishlist $wishlist,
        #[ORM\ManyToOne(targetEntity: OfferInterface::class)]
        #[ORM\JoinColumn(name: 'offer_id', referencedColumnName: 'id', nullable: false, onDelete: 'cascade')]
        private OfferInterface $offer,
    ) {
        $this->id = Uuid::v7();
        $this->createdAt = new \DateTimeImmutable();
    }

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

    public function getWishlist(): Wishlist
    {
        return $this->wishlist;
    }

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

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }
}
