<?php 

namespace App\Components;

class Field
{
    protected string $type;
    protected string $name;
    protected string $label;
    protected array $options = [];

    public static function make(): self
    {
        return new self();
    }

    public function type(string $type): self
    {
        $this->type = $type;
        return $this;
    }

    public function id(string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function label(string $label): self
    {
        $this->label = $label;
        return $this;
    }
    
    public function value($value): self
    {
        $this->options['value'] = $value;
        return $this;
    }

   public function options(array $options): self
    {
        $this->options = array_merge($this->options, $options);
        return $this;
    }

    public function toArray(): array
    {
        return [
            'type' => $this->type,
            'name' => $this->name,
            'label' => $this->label,
            'options' => $this->options,
        ];
    }
}