<?php

namespace Myrmidex\AnagramFinder;

use Illuminate\Support\Collection;

class ArgHandler
{
    private Collection $args;

    public function __construct(array $argv)
    {
        $this->args = new Collection($argv);
    }

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

    public function get(int $index)
    {
        return $this->args
            ->reject(fn ($word) => substr($word, 0, 2) === '--')
            ->get($index);
    }

    public function hasOption(string $option) {
        return $this->args
            ->filter(fn ($word) => $word === '--' . $option)
            ->isNotEmpty();
    }
}
