<?php

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');

// In environments without a persistent Supervisor daemon (e.g. local dev), queued jobs
// are processed by a short-lived `queue:work` invocation kicked off every minute by the scheduler.
// `withoutOverlapping()` ensures a still-running invocation (e.g. mid-Veo-render) blocks
// the next minute's attempt rather than running concurrent workers on the same queue.
// For production, a persistent Supervisor daemon is recommended (see docs/PRODUCTION-DEPLOYMENT.md).
Schedule::command('queue:work --queue='.config('queue.connections.database.queue', 'default').' --stop-when-empty --max-time=50')
    ->everyMinute()
    ->withoutOverlapping(10)
    ->runInBackground();

// Daily refresh of platform OAuth access tokens expiring within 10 days (Meta 60-day, LinkedIn, Google)
Schedule::command('platforms:refresh-tokens --days=10')
    ->daily()
    ->withoutOverlapping(10)
    ->runInBackground();
// Hourly campaign performance ingest (lifetime backfill, then 3h refresh)
Schedule::command('campaigns:sync-performance --hourly')
    ->hourly()
    ->withoutOverlapping(50)
    ->runInBackground();

// Daily campaign performance sync at 06:00
Schedule::command('campaigns:sync-performance')
    ->dailyAt('06:00')
    ->withoutOverlapping(120)
    ->runInBackground();

// Prune stale queue failures (older than 7 days) and batch metadata (older than 48 hours)
Schedule::command('queue:prune-failed --hours=168')->daily()->runInBackground();
Schedule::command('queue:prune-batches --hours=48')->daily()->runInBackground();
