<?php

namespace ModulesGarden\ProxmoxAddon\App\Cron;

use ModulesGarden\ProxmoxAddon\Core\CommandLine\AbstractCommand;
use ModulesGarden\ProxmoxAddon\Core\CommandLine\Hypervisor;
use ModulesGarden\ProxmoxAddon\Core\Queue\Models\Job;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
 * Class Queue
 * @package ModulesGarden\ProxmoxAddon\App\Cron
 */
class Queue extends AbstractCommand
{
    /**
     * Command name
     * @var string
     */
    protected $name = 'queue';

    /**
     * Command description
     * @var string
     */
    protected $description = 'Run module queue';

    /**
     * Command help text
     * @var string
     */
    protected $help = 'Just run that command to start all queued tasks!';

    /**
     * Configure command
     */
    protected function setup()
    {

    }

    /**
     * Run your custom code
     * @param InputInterface $inputCar
     * @param OutputInterface $output
     * @return int|null|void
     */
    protected function process(InputInterface $input, OutputInterface $output, SymfonyStyle $io)
    {
        $queue = new \ModulesGarden\ProxmoxAddon\Core\Queue\Queue();
        $queue->setCallBefore(function (Job $job) use ($input,$io)
        {
            $io->writeln("Running {$job->job}");
            (new Hypervisor($this->getName(), $input->getOptions()))
                ->ping();
        });
        $queue->process();
    }
}