<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Seka\Portal\Modul\Statistiky\Console\ImportZaznamovCommand;

/**
 * Class ScheduleServiceProvider
 *
 * @package Seka\Portal\Modul\Statistiky\Providers
 */
final class ScheduleServiceProvider extends ServiceProvider
{
    /**
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function boot(): void
    {
        $this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
            $schedule->command(
                ImportZaznamovCommand::class,
                ['storage/app/sftp/statistiky', 'storage/app/sftp/statistiky/importovane']
            )
                ->everyTwoHours()
                ->withoutOverlapping(10)
                ->onOneServer()
                ->runInBackground()
                ->emailOutputOnFailure(config('statistiky.import_email_address'));
        });
    }
}
