<?php

namespace App\Console;

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)
    {
        // $schedule->command('inspire')->hourly();
        //$schedule->command('cron:magicwands')->everyMinute(); //->withoutOverlapping();

        /*$jobs = Job::where('status', 1)->whereNotNull('command')->where('schedule', 'everyMinute')->get();
        foreach ($jobs as $job) {
            $schedule->command($job->command)->everyMinute()->withoutOverlapping();
        }*/
        //crontab -e
        //* * * * * cd /var/www/html/linkdata && php artisan schedule:run >> /dev/null 2>&1

        // Cancel expired provisional orders every hour
        // This checks for orders where identity verification deadline has passed
        $schedule->command('orders:cancel-expired-provisional --sync')
            ->hourly()
            ->withoutOverlapping()
            ->appendOutputTo(storage_path('logs/cancel-expired-orders.log'));

        // 着用日11日前の自動決済（毎日9時実行）
        $schedule->command('orders:charge-scheduled --sync')
            ->dailyAt('09:00')
            ->withoutOverlapping()
            ->appendOutputTo(storage_path('logs/charge-scheduled-payments.log'));

        // 保管料更新案内メール（毎日10時実行・更新1ヶ月前に送信）
        $schedule->command('storage:notify-renewal')
            ->dailyAt('10:00')
            ->withoutOverlapping()
            ->appendOutputTo(storage_path('logs/storage-notify-renewal.log'));

        // 保管料自動更新課金（毎日11時実行）
        $schedule->command('storage:renew')
            ->dailyAt('11:00')
            ->withoutOverlapping()
            ->appendOutputTo(storage_path('logs/storage-renew.log'));

        // 期限切れバーチャル試着結果のクリーンアップ（毎日深夜3時 JST 実行）
        $schedule->command('tryon:clean-expired')
            ->dailyAt('03:00')
            ->timezone('Asia/Tokyo')
            ->withoutOverlapping()
            ->appendOutputTo(storage_path('logs/clean-expired-tryon.log'));
    }

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

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