<?php

namespace KupShop\PohodaBundle\Command;

use KupShop\KupShopBundle\Util\System\PathFinder;
use KupShop\PohodaBundle\Utils\PohodaBase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class DownloadFileCommand extends command
{
    use PohodaBase;
    /**
     * @var PathFinder
     */
    protected $pathFinder;
    protected static $defaultName = 'shop:pohoda-download-file';

    protected function configure()
    {
        $this->addOption('path', 'p', InputOption::VALUE_REQUIRED, 'path on pohoda folder', false);
        $this->addOption('outputFile', 'o', InputOption::VALUE_REQUIRED, 'Save result file to /data.', false);
    }

    public function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Downloading started.');

        $url = $this->pathFinder->getDataDir().$input->getOption('outputFile');
        file_put_contents($url, $this->pohodaConnector->getPohodaFile($input->getOption('path')));

        return 0;
    }

    /**
     * @required
     */
    public function setPathFinder(PathFinder $pathFinder): void
    {
        $this->pathFinder = $pathFinder;
    }
}
