<?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.
     */
    protected function schedule(Schedule $schedule): void
    {
        // Expire promotions daily
        $schedule->call(function () {
            $expiredCount = \App\Models\ProductPromotion::where('status', 'active')
                ->where('end_date', '<', now())
                ->update(['status' => 'expired']);
                
            \Log::info("Expired {$expiredCount} promotions");
        })->daily();

        // Send subscription expiry reminders daily at 8 AM
        $schedule->command('subscriptions:send-expiry-reminders')->dailyAt('08:00');

        // Cleanup old data (Sellers & RFQs)
        $schedule->command('data:cleanup')->daily();
    }

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

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