<?php
/**
 * BookiFlex Payment Extension
 *
 * @package    BookiFlex
 * @subpackage Payment
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Extensions\Payment\Api\Request;

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

defined( 'ABSPATH' ) || exit;

class GetPrivateTokenRequest extends AbstractRequest
{
    public function __construct(
        private readonly string $reservationSid,
        private readonly int $paymentId
    ) {
    }

    public static function fromWpRestRequest(WP_REST_Request $request): self
    {
        $params = $request->get_json_params();

        return new self(
            reservationSid: (string) $params['reservationSid'],
            paymentId: (int) $params['paymentId']
        );
    }

    public static function getValidationRules(): array
    {
        return [
            'reservationSid' => [
                'required'          => true,
                'validate_callback' => fn($param) => Uuid::isValid($param),
                'sanitize_callback' => [self::class, 'sanitizeString'],
            ],
            'paymentId' => self::positiveIntRule(),
        ];
    }

    public function toArray(): array
    {
        return [
            'reservationSid' => $this->reservationSid,
            'paymentId' => $this->paymentId,
        ];
    }

    public function getReservationSid(): string
    {
        return $this->reservationSid;
    }

    public function getPaymentId(): int
    {
        return $this->paymentId;
    }
}
