<?php

use App\Models\EarnApiAccessLog;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
Schedule::command('serp:dispatch-due')->everyMinute()->withoutOverlapping()->onOneServer();
Schedule::command('serp:reconcile --execute')->everyFiveMinutes()->withoutOverlapping()->onOneServer();
Artisan::command('earn:prune-api-access-logs', function () {
    $cutoff = now()->subDays((int) config('earn.api.access_log_retention_days'));
    $deleted = EarnApiAccessLog::query()->where('occurred_at', '<', $cutoff)->delete();
    $this->info("Pruned {$deleted} Earn API access logs.");
})->purpose('Delete expired detailed Earn API access logs');
Schedule::command('earn:prune-api-access-logs')->dailyAt('03:20')->withoutOverlapping()->onOneServer();
