<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->command('backup:clean')->daily()->at('01:00');
        $schedule->command('backup:clean')->daily()->at('17:30');
        $schedule->command('backup:run')->daily()->at('08:00');
        //$schedule->command('backup:run')->daily()->at('12:00');
        //$schedule->command('backup:run')->daily()->at('17:00');
        $schedule->command('backup:run')->cron('0 */6 * * *');


        //$schedule->command('payments:check')->everyMinute();// job to check and update payments
        $schedule->command('payments:check')
            ->everyMinute()
            ->when(function () {
                $hour = now()->hour;
                return $hour >= 6 && $hour < 22; // Daytime (6am to 10pm)
            });

        $schedule->command('payments:check')
            ->everyTenMinutes()
            ->when(function () {
                $hour = now()->hour;
                return $hour >= 22 || $hour < 6; // Nighttime (10pm to 6am)
            });
        $schedule->command('command:updateexpiredcerts')->dailyAt('00:00');// Update expired certificates

         $schedule->command('certificates:clean-temp')
        ->twiceDaily(0, 12); // Midnight & Noon
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

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