<?php
/** Check SLA breaches for support tickets */
require_once dirname(__DIR__) . '/config.php';
try {
    // Mark SLA breaches
    db()->exec("UPDATE support_tickets SET sla_breach=1
        WHERE sla_breach=0 AND first_response_at IS NULL
        AND status IN ('open','in_progress')
        AND ((priority='urgent' AND created_at < NOW() - INTERVAL 4 HOUR)
          OR (priority='high' AND created_at < NOW() - INTERVAL 8 HOUR)
          OR (priority IN ('normal','low') AND created_at < NOW() - INTERVAL 24 HOUR))");
    echo date('Y-m-d H:i:s') . " SLA check done\n";
} catch (Throwable $e) { echo "ERROR: ".$e->getMessage()."\n"; }
