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

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

defined( 'ABSPATH' ) || exit;

class ResolvePenaltyRequest extends AbstractRequest
{
    public function __construct(
        private readonly int $id,
        private readonly ?string $comment
    ) {
    }

    /**
     * Create request from WP REST Request
     */
    public static function fromWpRestRequest(WP_REST_Request $request): self
    {
        return new self(
            id: (int) $request->get_param('id'),
            comment: $request->get_param('comment')
        );
    }

    /**
     * Get validation rules for WP REST API
     */
    public static function getValidationRules(): array
    {
        return [
            'id' => self::positiveIntRule(required: true),
            'comment' => [
                'required' => false,
                'type' => 'string',
                'default' => null,
                'sanitize_callback' => fn($value) => $value !== null ? self::sanitizeString($value) : null,
            ],
        ];
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function getComment(): ?string
    {
        return $this->comment;
    }
}
