<?php

declare(strict_types=1);

namespace Builder\Core\Foundation\Definition\Concerns;

use Closure;

trait HasOptions
{
    /** @var array<string, string>|Closure|null */
    private array|Closure|null $options = null;

    private bool $multiple = false;

    /** @param array<string, string>|Closure $options */
    public function options(array|Closure $options): self
    {
        $this->options = $options;

        return $this;
    }

    public function multiple(bool $value = true): self
    {
        $this->multiple = $value;

        return $this;
    }

    /** @return array<string, string>|null */
    public function getOptions(): ?array
    {
        if ($this->options === null) {
            return null;
        }

        if ($this->options instanceof Closure) {
            return ($this->options)();
        }

        return $this->options;
    }

    public function isMultiple(): bool
    {
        return $this->multiple;
    }
}
