<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\Inspire;
use App\Models\EmailBooking;
use App\Models\EmailBookingTest;
use App\Models\TestDB;
use App\Models\SyncToDynamics;
use App\Models\EmailCashReport;
use App\Models\FirebaseNotificationTest;
use App\Models\ElasticSearchTest;
use App\Models\FakeFeedback;
use App\Models\SendReminder;
use App\Models\SendTwilioSMSTest;
use App\Models\FeedbackReminderCommand;
use App\Models\InvoicePatchCommand;
use App\Models\PrebookReminderCommand;
use App\Models\ReadSMSCommand;
use App\Console\Commands\RepairsReminder;
use App\Console\Commands\ValidateControllerImports;
use App\Models\SaleLeadReminders;
use App\Models\ScheduledEmailsCommand;
use App\Models\SeraphSyncLabourCommand;
use App\Models\StatsExportCommand;
use App\Models\StockImportCommand;
use App\Models\StockSearchCommand;
use App\Models\SupportReminders;
use App\Models\SupportUntouchedReminders;
use App\Models\TaskAlarmNotification;
use App\Models\UntouchedReminderCommand;
use App\Models\ProcessTimeLogs;
use App\Models\SyncCrmContacts;
use App\Models\HolidayTesting;
use App\Models\StatsTest;
use App\Models\BeautifyOldComments;
use App\Models\EmailTest;
use App\Console\Commands\AuditModelColumns;


class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // 3CX WebSocket listener command
        \App\Console\Commands\ThreeCXWebSocketListener::class,
        \App\Console\Commands\ThreeCXWebSocketManager::class,
        \App\Console\Commands\ThreeCXWebSocketRunner::class,

        // Commands\Inspire::class,
        EmailBooking::class,
        EmailBookingTest::class,
        TestDB::class,
        mapHaniel::class,
        SyncToDynamics::class,
        EmailCashReport::class,
        FirebaseNotificationTest::class,
        ElasticSearchTest::class,
        \App\Console\Commands\OptimizePerformance::class,
        // Removed Kashflow command - using Xero integration instead
        FakeFeedback::class,
        SendReminder::class,
        SendTwilioSMSTest::class,
        FeedbackReminderCommand::class,
        InvoicePatchCommand::class,
        PrebookReminderCommand::class,
        ReadSMSCommand::class,
        RepairsReminder::class,
        SaleLeadReminders::class,
        ScheduledEmailsCommand::class,
        SeraphSyncLabourCommand::class,
        StatsExportCommand::class,
        StockImportCommand::class,
        StockSearchCommand::class,
        SupportReminders::class,
        SupportUntouchedReminders::class,
        TaskAlarmNotification::class,
        UntouchedReminderCommand::class,
        Commands\ProcessTimeLogs::class,
        Commands\SyncCrmContacts::class,
        HolidayTesting::class,
        StatsTest::class,
        BeautifyOldComments::class,
        fixlunchtimes::class,
        EmailTest::class,
        AuditModelColumns::class,
        ValidateControllerImports::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     *
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('process:timelogs')
                 ->dailyAt('00:05');
        
        // Check for email replies to existing tasks every 5 minutes (no new tasks, no emails sent)
        $schedule->command('bookings:email support --replies-only')
                 ->everyFiveMinutes()
                 ->withoutOverlapping()
                 ->runInBackground();
        
        // Check for repair email replies every 5 minutes (no new tasks, no emails sent)
        $schedule->command('bookings:email repair --replies-only')
                 ->everyFiveMinutes()
                 ->withoutOverlapping()
                 ->runInBackground();
    }
}
