// Poll cadence decisions, kept pure (no db imports) so vitest can load them.

export const POLL_INPLAY_MS = 8_000;
export const POLL_NEAR_MS = 20_000;
export const POLL_IDLE_MS = 10 * 60_000;

/** Three tiers: in-play → 8s, inside a kickoff window → 20s, otherwise 10m. */
export function pollDelay(anyLive: boolean, nearKickoff: boolean): number {
  if (anyLive) return POLL_INPLAY_MS;
  if (nearKickoff) return POLL_NEAR_MS;
  return POLL_IDLE_MS;
}

/** Throttle gate for the football-data fallback (hard 10 req/min free tier):
 *  allow at most one attempt per `intervalMs`, regardless of tick cadence. */
export function fallbackAllowed(lastAttempt: number, now: number, intervalMs = 15_000): boolean {
  return now - lastAttempt >= intervalMs;
}
