<?php

namespace App\Console;

use App\CentralLogics\Helpers;
use App\Services\Customer\CustomerQualityService;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $integration = Helpers::get_business_settings('courier_integration') ?? [];

        if (data_get($integration, 'enabled') && data_get($integration, 'auto_sync_enabled')) {
            $schedule->command('courier:sync-statuses --limit=50')
                ->everyThirtyMinutes()
                ->withoutOverlapping()
                ->runInBackground();
        }

        $schedule->command('courier:retry-out-for-delivery-sms --limit=50')
            ->everyTenMinutes()
            ->withoutOverlapping();

        $customerQualitySync = app(CustomerQualityService::class)->settings();
        if (data_get($customerQualitySync, 'auto_sync_enabled')) {
            $schedule->command('customer-quality:auto-sync')
                ->hourly()
                ->withoutOverlapping()
                ->runInBackground();
        }

    }

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

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