<?php

namespace App\Framework\Console;

/**
 * Fluent builder for ArgumentParser
 */
final class ArgumentParserBuilder
{
    /** @var ArgumentDefinition[] */
    private array $definitions = [];

    public function addArgument(ArgumentDefinition $definition): self
    {
        $this->definitions[$definition->name] = $definition;

        return $this;
    }

    public function requiredString(string $name, string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::required($name, $description));
    }

    public function optionalString(string $name, string $default = '', string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::optional($name, $default, $description));
    }

    public function flag(string $name, ?string $shortName = null, string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::flag($name, $shortName, $description));
    }

    public function email(string $name, bool $required = true, string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::email($name, $required, $description));
    }

    public function integer(string $name, bool $required = false, ?int $default = null, string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::integer($name, $required, $default, $description));
    }

    public function choice(string $name, array $choices, bool $required = false, ?string $default = null, string $description = ''): self
    {
        return $this->addArgument(ArgumentDefinition::choice($name, $choices, $required, $default, $description));
    }

    public function build(): ArgumentParser
    {
        return new ArgumentParser($this->definitions);
    }
}
