<?php

namespace Plainwork\Ui\Component\Form;

use Plainwork\Http\Request;

abstract class AbstractFieldset implements InputInterface
{
    private string $name;
    private array $errors = [];
    private array $helps = [];
    private bool $required = false;
    private $requiredLabel = null;
    private bool $disabled = false;

    abstract public function grab(Request $request);

    final public function __construct(string $name)
    {
        $this->setName($name);
    }

    public function setName(string $v): self
    {
        $this->name = $v;

        return $this;
    }

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

    public function addError($error): self
    {
        $this->errors[] = $error;

        return $this;
    }

    public function getErrors(): array
    {
        return $this->errors;
    }

    public function addHelp($help): self
    {
        $this->helps[] = $help;

        return $this;
    }

    public function getHelps(): array
    {
        return $this->helps;
    }

    public function isRequired(): bool
    {
        return $this->required;
    }

    public function setRequired($label = '__Required field__'): self
    {
        $this->required = true;
        $this->requiredLabel = $label;

        return $this;
    }

    public function getRequiredLabel()
    {
        return $this->requiredLabel;
    }

    public function isDisabled(): bool
    {
        return $this->disabled;
    }

    public function setDisabled(bool $v = true): self
    {
        $this->disabled = $v;

        return $this;
    }
}
