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

defined( 'ABSPATH' ) || exit;

/**
 * Represents one possible placement scenario
 */
final class PlacementScenario
{
    private string $kind; // 'adults' or 'children'
    private int $mainPlaces;
    private int $extraPlaces;
    private array $metadata;

    public function __construct(
        string $kind,
        int $mainPlaces,
        int $extraPlaces,
        array $metadata = []
    ) {
        if (!in_array($kind, ['adults', 'children'])) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Invalid scenario kind: %s',
                    $kind
                )
            );
        }

        $this->kind = $kind;
        $this->mainPlaces = $mainPlaces;
        $this->extraPlaces = $extraPlaces;
        $this->metadata = $metadata;
    }

    public function getKind(): string
    {
        return $this->kind;
    }

    public function getMainPlaces(): int
    {
        return $this->mainPlaces;
    }

    public function getExtraPlaces(): int
    {
        return $this->extraPlaces;
    }

    public function getTotalGuests(): int
    {
        return $this->mainPlaces + $this->extraPlaces;
    }

    public function getMetadata(): array
    {
        return $this->metadata;
    }

    public function isAdultsOnly(): bool
    {
        return $this->kind === 'adults';
    }

    public function allowsChildren(): bool
    {
        return $this->kind === 'children';
    }

    public function toArray(): array
    {
        return [
            'kind' => $this->kind,
            'main' => $this->mainPlaces,
            'extra' => $this->extraPlaces
        ];
    }
}
