<?php

namespace Opentalent\OtAdmin\Command;


use Opentalent\OtAdmin\Controller\SiteController;
use Opentalent\OtCore\Exception\NoSuchOrganizationException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
 * This CLI command create or update the organization config file, and update the identifier field in ot_websites table
 * This is a light alternative to the update command, designed to be executed on a development env, just after
 * the databases cloning.
 *
 * @package Opentalent\OtAdmin\Command
 */
class RegenConfigFilesCommand extends Command
{
    public function __construct(
        private readonly SiteController $siteController
    ) {
        parent::__construct();
    }

    /**
     * -- This method is expected by Typo3, do not rename ou remove --
     *
     * Allows to configure the command.
     * Allows to add a description, a help text, and / or define arguments.
     *
     */
    protected function configure()
    {
        $this
            ->setName("ot:regen-config-files")
            ->setDescription("Recreate all of the website config files with the Db data");
    }

    /**
     * -- This method is expected by Typo3, do not rename ou remove --
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     * @throws \Exception
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $this->siteController->regenConfigFilesAction();
        $io->success(sprintf("The config files were recreated"));
        return 0;
    }
}
