<?php

declare(strict_types=1);

namespace Apexl\Io\Cron\Commands;

use Apexl\Io\Cron\Actions\RunCron;
use Apexl\Io\System\Commands\DaedalusCommand;
use DI\Container;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

#[AsCommand(name: 'cron:run', description: 'Run cron tasks')]
class RunCronTasksCommand extends DaedalusCommand
{
    public function __construct(
        private readonly Container $container,
        private readonly RunCron $runCron,
        ?string $name = null
    ) {
        parent::__construct($name);
    }

    /**
     * @throws Throwable
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->container->call($this->runCron->run(...));

        return Command::SUCCESS;
    }
}
