// Fallback cron + concurrency constants for scheduled join-link generation.
export const JOIN_LINK_GENERATION = {
  /** Fallback safety-net cron: every 4 hours (top of the hour). */
  FALLBACK_CRON: '0 */4 * * *',
  /**
   * Grace after a session's fire time before the fallback cron may claim it.
   * Keeps the cron from stealing a just-fired AWS event that is still in flight.
   */
  GRACE_MS: 30 * 60 * 1000,
  /**
   * An IN_PROGRESS older than this is treated as a crashed run and is
   * re-claimable. A healthy run flips to COMPLETED/FAILED in seconds, so this
   * only ever reclaims genuinely stuck sessions.
   */
  STALE_MS: 30 * 60 * 1000,
  /** Max sessions processed per cron tick (bounds the fan-out of bulk jobs). */
  FALLBACK_BATCH_LIMIT: 50,
  /**
   * After dispatching the bulk job, generateForSession polls it to a terminal
   * state so the session status reflects the real outcome (not just dispatch).
   * Poll every JOB_POLL_INTERVAL_MS, up to JOB_POLL_MAX_ATTEMPTS (~5 min). A
   * healthy run finishes in seconds; exceeding the cap leaves the session
   * IN_PROGRESS for the stale-reclaim backstop.
   */
  JOB_POLL_INTERVAL_MS: 2000,
  JOB_POLL_MAX_ATTEMPTS: 150,
} as const;

export const JOIN_LINK_GENERATION_LOG = {
  FALLBACK_DISABLED:
    'Join-link fallback cron disabled (ENABLE_JOIN_LINK_FALLBACK_CRON!=true); skipping sweep',
  FALLBACK_FOUND: (count: number): string =>
    `Join-link fallback sweep: ${count} overdue session(s) to re-attempt`,
  FALLBACK_ITEM_FAILED: (id: number): string =>
    `Join-link fallback generation failed for session ${id}`,
  FALLBACK_SWEEP_FAILED: 'Join-link fallback sweep failed',
} as const;
