<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Core\Model\AccommodationType\Placement;

use BookiFlex\Core\Model\AccommodationType\Guest\GuestType;
use BookiFlex\Core\ValueObject\PlacementLocation;
use Brick\Money\Money;

defined( 'ABSPATH' ) || exit;

/**
 * Placement option for a specific guest type and location
 */
final class PlacementOption
{
    private GuestType $guestType;
    private PlacementLocation $location;
    private bool $allowed;
    private ?Money $price;

    public function __construct(
        GuestType $guestType,
        PlacementLocation $location,
        bool $allowed = false,
        ?Money $price = null
    ) {
        $this->guestType = $guestType;
        $this->location = $location;
        $this->allowed = $allowed;
        $this->price = $price;
    }

    public function getGuestType(): GuestType
    {
        return $this->guestType;
    }

    public function getLocation(): PlacementLocation
    {
        return $this->location;
    }

    public function isAllowed(): bool
    {
        return $this->allowed;
    }

    public function getPrice(): ?Money
    {
        return $this->price;
    }

    public function withPrice(Money $price): self
    {
        return new self($this->guestType, $this->location, $this->allowed, $price);
    }

    public function allow(): self
    {
        return new self($this->guestType, $this->location, true, $this->price);
    }

    public function getKey(): string
    {
        return $this->guestType->getTypeKey() . '_' . $this->location->toString();
    }
}
