<?php
namespace App\Console\Command;

use App;
use App\Sync\Runner;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Sync extends \App\Console\Command\CommandAbstract
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->setName('sync:run')
            ->setDescription('Run one or more scheduled synchronization tasks.')
            ->addArgument(
                'task',
                InputArgument::OPTIONAL,
                'The task to run (nowplaying,short,medium,long).',
                'nowplaying'
            );
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var Runner $sync */
        $sync = $this->get(Runner::class);

        switch ($input->getArgument('task')) {
            case 'long':
                $output->writeln('Running Long (1-hour) Sync...');

                $sync->syncLong();
                break;

            case 'medium':
                $output->writeln('Running Medium (5-minutes) Sync...');

                $sync->syncMedium();
                break;

            case 'short':
                $output->writeln('Running Short (1-minute) Sync...');

                $sync->syncShort();
                break;

            case 'nowplaying':
            default:
                $output->writeln('Running Now-Playing (15-second) Sync...');

                define('NOWPLAYING_SEGMENT', 1);
                $sync->syncNowplaying();
                break;
        }

        return 0;
    }
}
