<?php

require_once __DIR__ . '/_bootstrap.php';
$auth = agent_sync_authenticate($conn);
$instanceEsc = $conn->real_escape_string($auth['instance_id']);
$rs = @$conn->query("SELECT status,COUNT(*) total FROM agent_sync_events WHERE instance_id='{$instanceEsc}' GROUP BY status");
$counts = [];
if ($rs) while ($row = $rs->fetch_assoc()) $counts[$row['status']] = (int)$row['total'];
agent_sync_reply(200, ['ok'=>true,'agent_id'=>(int)$auth['agent']['id'],'instance_id'=>$auth['instance_id'],'counts'=>$counts,'server_time'=>time()]);
