/**
 * Shared transport limits and timings (ARCHITECTURE §4). Client and server import the same numbers
 * so retry behaviour never fights the server's throttles.
 */

/** Token bucket per socket: refill `perSecond`, hold at most `burst`. */
export const RATE_LIMIT = { perSecond: 8, burst: 16 } as const;

/** Live connections per IP. Generous because a whole bar shares one Wi-Fi NAT address. */
export const MAX_CONNECTIONS_PER_IP = 300;

/** Upper bound for one inbound Socket.IO message (`maxHttpBufferSize`); real payloads are < 1 KiB. */
export const MAX_CLIENT_MESSAGE_BYTES = 16 * 1024;

/** Answer counts / join lists are broadcast at most twice per second. */
export const BROADCAST_THROTTLE_MS = 500;

/** Client-side resync policy for `state.request` (sent on reconnect or when a `seq` gap is seen). */
export const RESYNC = {
  /** Retry `state.request` if its ack has not arrived by then. */
  ackTimeoutMs: 5_000,
  /** Exponential backoff between retries: base, doubled per attempt, capped. */
  retryBaseMs: 500,
  retryMaxMs: 8_000,
  /** Coalesce gap-triggered requests: at most one per this interval per socket. */
  minIntervalMs: 1_000,
  /** Request a snapshot if nothing arrived this long after a phase deadline passed (missed message). */
  staleAfterMs: 10_000,
} as const;

/** `clock.sync` sampling: take the lowest-RTT of `samples` round-trips, refresh periodically. */
export const CLOCK_SYNC = {
  samples: 5,
  refreshMs: 60_000,
} as const;
