<?php

namespace Lucent\Schema\Ui;

use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;

class File implements FieldInterface, MinMaxInterface
{
    public FieldInfo $info;


    /**
     * @param string[] $collections
     */
    public function __construct(
        public string $name,
        public string $label,
        public string $mime = "",
        public string $help = "",
        public ?int   $min = null,
        public ?int   $max = null,
        public array  $collections = [],
        public string $group = "",
    )
    {
        $this->info = new FieldInfo("file", "File", FieldType::FILE);
    }

    public function format(array $input, array $output): array
    {
        return $output;
    }

    public function failMin(mixed $value): bool
    {
        if (is_null($value)) {
            return false;
        }

        return count($value) < $this->min;
    }

    public function failMax(mixed $value): bool
    {
        if (is_null($value)) {
            return false;
        }

        return count($value) < $this->min;
    }

}

