<?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\Api\Request\DateUnit;

use BookiFlex\Core\Api\Request\AbstractRequest;
use WP_REST_Request;

defined( 'ABSPATH' ) || exit;

class SyncDateUnitsRequest extends AbstractRequest
{
    public function __construct(
        private readonly int $ratePlanId,
        private readonly int $accommodationTypeId
    ) {
    }

    /**
     * Create request from WP REST Request
     */
    public static function fromWpRestRequest(WP_REST_Request $request): self
    {
        $params = $request->get_params();

        return new self(
            ratePlanId: (int) $params['ratePlan'],
            accommodationTypeId: (int) $params['accommodationType']
        );
    }

    /**
     * Get validation rules for WP REST API
     */
    public static function getValidationRules(): array
    {
        return [
            'ratePlan' => self::positiveIntRule(required: true),
            'accommodationType' => self::positiveIntRule(required: true),
        ];
    }

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

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