<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Http\Controllers\Backend;

use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Artisan;
use Seka\Portal\Modul\Statistiky\Http\Controllers\Controller;

/**
 * Class SpustitImport
 *
 * @package Seka\Portal\Modul\Statistiky\Http\Controllers\Backend
 */
final class SpustitImport extends Controller
{
    /**
     * @return \Illuminate\Http\RedirectResponse
     */
    public function __invoke()
    {
        try {
            Artisan::queue('statistiky:import', [
                'cesta' => 'storage/app/sftp/statistiky',
                'presunutdo' => 'storage/app/sftp/statistiky/importovane',
                '--pocet' => 1,
            ])->onQueue('long-time-job-queue');
        } catch (Exception $e) {
            Log::error($e->getMessage(), $e->getTrace());

            flash()->error('Chyba pri spustení importu.');
        } finally {
            return back();
        }
    }
}
