<?php
namespace PpPhp\Plugins;

use PpPhp\Core\ValidationPlugin;

class RequiredRule implements ValidationPlugin
{
    public static function id(): string { return 'required'; }
    public static function label(): string { return 'Required'; }
    public static function group(): string { return 'Presence'; }
    public static function paramsSchema(): array { return []; }
    public static function appliesTo(): array { return []; }
    public static function defaultMessage(): string { return '{label} is required.'; }
    public static function validatesEmpty(): bool { return true; }

    public static function serverCheck(mixed $value, array $params, array $record = []): bool
    {
        if ($value === null) return false;
        if (is_array($value)) return $value !== [];
        return trim((string) $value) !== '';
    }

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