<?php

namespace App\Console;

use App\Models\Configuration;
use App\Models\exchangeRate;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->command('milestone:due')->daily();
        $schedule->command('money:payout')->daily();
        $invoicesCommandFlag = Configuration::where('key', 'exchange_rate_auto_update')->first();
        if($invoicesCommandFlag && $invoicesCommandFlag->value == 'true') {
            $schedule->call(function () {
                exchangeRate::getCurrentRatesInUSD();
            })->daily();
        }


    }

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

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