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

use BookiFlex\Core\Api\Request\AbstractRequest;
use Symfony\Component\Uid\Uuid;
use WP_REST_Request;

defined( 'ABSPATH' ) || exit;

class GetReservationRequest extends AbstractRequest
{
    private readonly Uuid $sid;

    public function __construct(
        Uuid|string $sid
    ) {
        $this->sid = is_string($sid) ? Uuid::fromString($sid) : $sid;
    }

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

        return new self(
            sid: $params['sid']
        );
    }

    /**
     * Get validation rules for WP REST API
     */
    public static function getValidationRules(): array
    {
        return [
            'sid' => [
                'required' => true,
                'type' => 'string',
                'validate_callback' => function ($value) {
                    if (!is_string($value)) {
                        return false;
                    }

                    return Uuid::isValid($value);
                },
                'sanitize_callback' => function ($value) {
                    return self::sanitizeString($value);
                },
            ],
        ];
    }

    public function getSid(): Uuid
    {
        return $this->sid;
    }

    public function getSidAsString(): string
    {
        return $this->sid->toRfc4122();
    }
}
