<?php

namespace App\Validation;

class CustomRules
{
    public function at_least_one($value, ?string $params = null, array $data = []): bool
    {
        if (is_array($value)) {
            $clean = array_values(array_filter(array_map(
                fn($v) => is_scalar($v) ? trim((string) $v) : '',
                $value
            ), fn($v) => $v !== ''));
            return count($clean) >= 1;
        }

        if (is_string($value)) {
            $v = trim($value);
            if ($v === '')
                return false;

            $parts = array_values(array_filter(array_map(
                fn($x) => trim((string) $x),
                explode(DEFAULTS["DELIMITER_COMMA"], $v)
            ), fn($x) => $x !== ''));

            return count($parts) >= 1;
        }

        return false;
    }
}
