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

/**
 * Collection of placement scenarios
 */
final class PlacementScenarioCollection implements \IteratorAggregate, \Countable
{
    /** @var PlacementScenario[] */
    private array $scenarios = [];

    public function add(PlacementScenario $scenario): void
    {
        $this->scenarios[] = $scenario;
    }

    public function getAdultScenarios(): array
    {
        return array_filter(
            $this->scenarios,
            fn($s) => $s->isAdultsOnly()
        );
    }

    public function getChildrenScenarios(): array
    {
        return array_filter(
            $this->scenarios,
            fn($s) => $s->allowsChildren()
        );
    }

    public function toArray(): array
    {
        return array_map(
            fn($scenario) => $scenario->toArray(),
            $this->scenarios
        );
    }

    public function getIterator(): \ArrayIterator
    {
        return new \ArrayIterator($this->scenarios);
    }

    public function count(): int
    {
        return count($this->scenarios);
    }
}
