<?php
require_once __DIR__.'/_auth.php';
$admin = afAdminApiUser($pdo);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $d = requestJson();
    try {
        afStage24ResolveAlert($pdo, (int)($d['alerta_id'] ?? 0), (int)$admin['id'], (string)($d['status'] ?? 'resolved'), sanitize($d['nota'] ?? ''));
        jsonResponse(['ok'=>true]);
    } catch (Throwable $e) {
        jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],422);
    }
}
$status = (string)($_GET['status'] ?? 'open');
$items = afStage24ListAlerts($pdo, $status, max(1, min(200, (int)($_GET['limit'] ?? 80))));
jsonResponse(['ok'=>true,'stage24'=>STAGE24_AUDIT_VERSION,'alertas'=>$items]);
