<?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\Service\DateUnit\DTO;

defined( 'ABSPATH' ) || exit;

class UpdateDateUnits
{
    /**
     * @param int $ratePlanId
     * @param int $accommodationTypeId
     * @param array $dates [
     *      [
     *          dateFrom: string of 'YYYY-MM-DD',
     *          dateTo: null | string of 'YYYY-MM-DD',
     *          mon: bool,
     *          tue: bool,
     *          wed: bool,
     *          thu: bool,
     *          fri: bool,
     *          sat: bool,
     *          sun: bool
     *      ]
     * ]
     * @param array|null $restrictions [
     *      'stopSale' | 'cta' | 'ctd': null | bool
     *      'minLos' | 'maxLos' | 'minLosArrival' | 'maxLosArrival' | 'minAdvBooking' | 'maxAdvBooking': null | int
     * ]
     * @param array|null $prices [
     *      [
     *          variant: string,
     *          scenario: string of 'adultOnMainPlace' | 'adultOnExtraPlace' | 'childOnMainPlace' | 'childOnExtraPlace' | 'childWithoutPlace',
     *          value: string,
     *          cancel: bool
     *      ]
     * ]
     */
    public function __construct(
        private readonly int $ratePlanId,
        private readonly int $accommodationTypeId,
        private readonly array $dates,
        private readonly ?array $restrictions = null,
        private readonly ?array $prices = null
    ) {
    }

    /**
     * Create from array (backward compatibility)
     */
    public static function fromArray(array $data): self
    {
        return new self(
            ratePlanId: (int) ($data['ratePlan'] ?? $data['ratePlanId'] ?? 0),
            accommodationTypeId: (int) ($data['accommodationType'] ?? $data['accommodationTypeId'] ?? 0),
            dates: $data['dates'] ?? [],
            restrictions: $data['restrictions'] ?? null,
            prices: $data['prices'] ?? null
        );
    }

    public function getRatePlanId(): int
    {
        return $this->ratePlanId;
    }

    public function getAccommodationTypeId(): int
    {
        return $this->accommodationTypeId;
    }

    public function getDates(): array
    {
        return $this->dates;
    }

    public function getRestrictions(): ?array
    {
        return $this->restrictions;
    }

    public function getPrices(): ?array
    {
        return $this->prices;
    }
}
