<?php

use App\Models\TerminalSession;
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');

// Enforce the audit-log retention policy daily. The command is a no-op when
// `audit_retention_days` is empty/0 (keep forever); otherwise it deletes
// audit_events older than the configured number of days.
Schedule::command('clusev:prune-audit')->daily();

// Sample WireGuard peer traffic every minute (no-op when the collector is unconfigured/stale).
Schedule::command('clusev:wg-sample')->everyMinute();

// Persist a one-per-minute resource history sample per server (and prune old samples). Reads the
// live cached reading the 15s poller keeps fresh — the long history the Server-Details graph plots.
Schedule::command('clusev:sample-metrics')->everyMinute();

// Refresh the cached latest-release tag so the sidebar update badge stays warm (cache TTL is 60 min).
Schedule::command('clusev:check-update')->everyThirtyMinutes();

// Sweep terminal-session tokens daily. They are single-use and expire in 60s, so any row older than a
// day is spent/dead — this keeps the table from growing unbounded over the panel's lifetime.
Schedule::call(fn () => TerminalSession::where('created_at', '<', now()->subDay())->delete())->daily();
