<?php

namespace App\Command;

use App\Entity\Client;
use App\Entity\Trace;
use App\Model\CommandTypes;
use App\Model\TraceStatus;
use Doctrine\ORM\EntityManagerInterface;
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\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'opengnsys:load-traces', description: 'Load traces')]
class ChargeExampleTraceCommand extends Command
{
    public function __construct(
        private readonly EntityManagerInterface $entityManager
    )
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $clients = $this->entityManager->getRepository(Client::class)->findAll();
        $traces = TraceStatus::getStatusKeys();

        foreach ($clients as $client) {
            foreach ($traces as $traceStatus) {
                $trace = new Trace();
                $trace->setClient($client);
                $trace->setJobId('CreateAuxiliarFiles_' . $client->getId());
                $trace->setStatus($traceStatus);
                $trace->setCommand(CommandTypes::CREATE_IMAGE_AUX_FILE);
                $trace->setExecutedAt(new \DateTime());
                $this->entityManager->persist($trace);
            }
        }

        $this->entityManager->flush();

        return Command::SUCCESS;
    }
}
