<?php
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/lib/rounds.php';
require_login();

header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');

$sinceId = v_int($_GET['since'] ?? 0, 0, PHP_INT_MAX, 0);
$user    = current_user();

try {
    $state = round_state_snapshot_for_user($pdo, $user);
    $bells = bell_recent_for_user($pdo, $user, $sinceId, 50);
    echo json_encode(['ok' => true, 'round' => $state, 'bells' => $bells]);
} catch (Throwable $e) {
    error_log('bell_state: ' . $e->getMessage());
    http_response_code(500);
    echo json_encode(['ok' => false, 'error' => 'server_error']);
}
