<?php

use App\Jobs\LiveChat\ReleaseStaleHumanRequestsJob;
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');

// Daily re-crawl of indexed sources older than 7 days. Avoids cf rate limits
// by capping the batch and stagger-dispatching inside CrawlSourceJob.
Schedule::command('pitchbar:refresh-stale-sources --days=7 --limit=200')
    ->dailyAt('03:30')
    ->withoutOverlapping()
    ->runInBackground();

// Weekly self-improvement: turn recurring unanswered questions into draft
// curated answers for the workspace owner to approve.
Schedule::command('pitchbar:suggest-from-gaps --min-occurrences=3')
    ->weeklyOn(1, '04:00')
    ->withoutOverlapping()
    ->runInBackground();

// Hourly delta sync for OAuth sources (Notion pages, Google Docs).
// Website crawls run weekly via pitchbar:refresh-stale-sources; this hits
// the integrations users expect to update much faster.
Schedule::command('pitchbar:sync-oauth-sources --hours=1 --limit=500')
    ->hourly()
    ->withoutOverlapping()
    ->runInBackground();

// Live-chat auto-fallback: release "needs human" conversations that
// have been waiting for more than 5 minutes and resume the bot with
// a "we'll follow up" message. Without this, an after-hours visitor
// would sit on a holding bubble indefinitely if no operator joins.
Schedule::job(new ReleaseStaleHumanRequestsJob)
    ->everyMinute()
    ->withoutOverlapping();
