<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\TicketBundle\Command;

use Chill\TicketBundle\Service\Import\ImportMotivesFromDirectory;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'chill:ticket:import_ticket_motive_configuration', description: 'Import ticket motives from a directory configuration.')]
class ImportTicketMotiveConfigurationCommand extends Command
{
    protected static $defaultName = 'chill:ticket:import_ticket_motive_configuration';

    public function __construct(private readonly ImportMotivesFromDirectory $importMotivesFromDirectory)
    {
        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->setDescription('Import ticket motives from a directory containing motives.yaml and referenced files')
            ->addArgument('directory', InputArgument::REQUIRED, 'The directory path containing motives.yaml')
            ->addArgument('lang', InputArgument::REQUIRED, 'The language key to use for matching labels (e.g., fr)');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $directory = (string) $input->getArgument('directory');
        $lang = (string) $input->getArgument('lang');

        $this->importMotivesFromDirectory->import($directory, $lang);

        $output->writeln('<info>Ticket motives import completed successfully.</info>');

        return Command::SUCCESS;
    }
}
