<?php
declare(strict_types=1);

namespace App\Services;

use App\Core\Database;

final class CronLogService
{
    public static function record(string $jobKey, string $status, ?string $message = null, ?int $durationMs = null): void
    {
        $db = Database::getInstance();
        $st = $db->prepare("
            INSERT INTO cron_runs (job_key, status, message, duration_ms)
            VALUES (:job_key, :status, :message, :duration_ms)
        ");
        $st->execute([
            ':job_key' => $jobKey,
            ':status' => $status === 'failed' ? 'failed' : 'success',
            ':message' => $message,
            ':duration_ms' => $durationMs,
        ]);
    }
}
