<?php

namespace Dalten\RuianToUir\Command;

use Dalten\RuianToUir\Converter\Field\PointCoordinatesConverter;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConvertCoords extends BaseCommand
{
    public function __construct(protected PointCoordinatesConverter $converter)
    {
        parent::__construct();
    }

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        $coords = $io->ask('Enter S-JTSK coords to convert (or . to stop):', '.');

        if (!\is_string($coords)) {
            throw new \InvalidArgumentException('Coords must be a string, '.\gettype($coords).' given.');
        }

        while ('.' !== $coords) {
            $io->text($this->converter->convertCoords($coords));
            $coords = $io->ask('Enter S-JTSK coords to convert (or . to stop):', '.');
        }

        return 0;
    }

    protected function configure(): void
    {
        $this->setName('convert-coords');
        $this->setDescription('Převede S-JTSK souřadnice na GPS.');
    }
}
