<?php

declare(strict_types=1);

namespace apexl\Io\modules\validation\PhpValidatorRules;

use BlakvGhost\PHPValidator\Contracts\Rule;

final readonly class JsonValidatesRule implements Rule
{
    public function __construct(array $parameters) {}

    public function passes(string $field, mixed $value, array $data): bool
    {
        return is_string($value) && json_validate($value);
    }

    public function message(): string
    {
        return ':field must be valid JSON.';
    }
}