<?php

namespace App\Console;

use App\Console\Commands\AgencyManagementReportCommand;
use App\Console\Commands\CheckApiSdkCommand;
use App\Console\Commands\DiscoverAccountsCommand;
use App\Console\Commands\DataQualityCommand;
use App\Console\Commands\FirstReportWizardCommand;
use App\Console\Commands\GenerateDailyWorkflowCommand;
use App\Console\Commands\HealthScoreCommand;
use App\Console\Commands\OperationDigestCommand;
use App\Console\Commands\PreviewConnectionDataCommand;
use App\Console\Commands\DwDoctorCommand;
use App\Console\Commands\EvaluateAlertRulesCommand;
use App\Console\Commands\GenerateAiInsightsCommand;
use App\Console\Commands\GenerateReportCommand;
use App\Console\Commands\RunScheduledReportsCommand;
use App\Console\Commands\SendReportCommand;
use App\Console\Commands\SendAgencyManagementReportCommand;
use App\Console\Commands\BuildNotificationCenterCommand;
use App\Console\Commands\SyncPlatformDataCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        BuildNotificationCenterCommand::class,
        SyncPlatformDataCommand::class,
        GenerateReportCommand::class,
        SendReportCommand::class,
        RunScheduledReportsCommand::class,
        EvaluateAlertRulesCommand::class,
        GenerateAiInsightsCommand::class,
        DwDoctorCommand::class,
        CheckApiSdkCommand::class,
        DiscoverAccountsCommand::class,
        PreviewConnectionDataCommand::class,
        DataQualityCommand::class,
        FirstReportWizardCommand::class,
        OperationDigestCommand::class,
        GenerateDailyWorkflowCommand::class,
        HealthScoreCommand::class,
        AgencyManagementReportCommand::class,
        SendAgencyManagementReportCommand::class,
    ];

    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('dw:sync-platform --from=yesterday --to=yesterday')
            ->dailyAt('03:15')
            ->withoutOverlapping();

        $schedule->command('dw:run-scheduled-reports')
            ->everyFiveMinutes()
            ->withoutOverlapping();

        $schedule->command('dw:evaluate-alerts')
            ->hourlyAt(20)
            ->withoutOverlapping();

        $schedule->command('dw:data-quality --from=yesterday --to=yesterday --save')
            ->dailyAt('04:15')
            ->withoutOverlapping();

        $schedule->command('dw:generate-ai-insights --latest=20 --regenerate-files')
            ->dailyAt('05:30')
            ->withoutOverlapping();

        $schedule->command('dw:daily-workflow --readiness=critical')
            ->dailyAt('08:00')
            ->withoutOverlapping();

        $schedule->command('dw:health-scores --status=active --save')
            ->dailyAt('08:20')
            ->withoutOverlapping();

        $schedule->command('dw:agency-report --period=weekly')
            ->weeklyOn(1, '08:45')
            ->withoutOverlapping();

        $schedule->command('dw:send-agency-report --period=weekly --generate')
            ->weeklyOn(1, '09:05')
            ->withoutOverlapping();

        $schedule->command('dw:agency-report --period=monthly')
            ->monthlyOn(1, '09:15')
            ->withoutOverlapping();

        $schedule->command('dw:send-agency-report --period=monthly --generate')
            ->monthlyOn(1, '09:35')
            ->withoutOverlapping();
    }

    protected function commands(): void
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
