<?php
namespace Helpers\Form;

class FormInput
{

    private string $label = '';
    private string $name;
    /** @var array<callable> */
    private array $listValidator = [];

//_____________________________________________________________________________
// Constructor

    public function __construct(string $name, string $label)
    {
        $this->name = $name;
        $this->label = $label;
    }

//_____________________________________________________________________________
// Accessor

    public function getName() :string
    {
        return $this->name;
    }

    public function getType() :string
    {
        return 'text';
    }

    public function getLabel() :string
    {
        return $this->label;
    }

    /**
     * @return array<callable>
     */
    public function listValidator() :array
    {
        return $this->listValidator;
    }
    
//_____________________________________________________________________________
// Modifier

    /**
     * @param callable(\Helpers\Validator\Validator, FormInput, mixed &$value, mixed $root):void $vali
     */
    public function addVali(callable $vali) :self
    {
        $this->listValidator[] = $vali;
        return $this;
    }


//_____________________________________________________________________________
// Shorthand

    // public function addValiStringSansEspace(string $method, int $min, int $max) :self
    // {
    //     $this->listValidator[ $method ] = ['min' => $min, 'max' => $max];
    //     return $this;
    // }
}
