<?php
namespace PpPhp\Plugins;

use PpPhp\Core\ValidationPlugin;

class MustAcceptRule implements ValidationPlugin
{
    public static function id(): string { return 'mustAccept'; }
    public static function label(): string { return 'Must be checked (accept)'; }
    public static function group(): string { return 'Presence'; }
    public static function paramsSchema(): array { return []; }
    public static function appliesTo(): array { return ['checkbox', 'toggle']; }
    public static function defaultMessage(): string { return 'You must accept to continue.'; }
    public static function validatesEmpty(): bool { return true; }

    public static function serverCheck(mixed $value, array $params, array $record = []): bool
    {
        return in_array(strtolower(trim((string) $value)), ['1', 'yes', 'true', 'on', 'checked'], true);
    }

    public static function clientRule(array $params): array
    {
        return ['checked' => true];
    }
}
