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


declare(strict_types=1);
namespace BookiFlex\Extensions\Cart\Api\Request;

use BookiFlex\Core\Api\Request\AbstractRequest;

defined( 'ABSPATH' ) || exit;

class RemoveFromCartRequest extends AbstractRequest
{
    public function __construct(
        private readonly string $hash
    ) {
    }

    public static function fromWpRestRequest(\WP_REST_Request $request): self
    {
        return new self(
            hash: $request->get_param('hash')
        );
    }

    public static function getValidationRules(): array
    {
        return [
            'hash' => [
                'required' => true,
                'validate_callback' => fn($value) => is_string($value) && preg_match('/^[a-zA-Z0-9]+$/', $value),
                'sanitize_callback' => 'sanitize_text_field',
            ],
        ];
    }

    public function getHash(): string
    {
        return $this->hash;
    }
}
