import { apiRoute } from '@/lib/api/handler'
import { buildLiveSnapshot } from '@/lib/services/live-snapshot'

export const dynamic = 'force-dynamic'

/** The current national picture — the same payload the live stream pushes. */
export const GET = apiRoute({ permission: 'grid.read' }, async ({ searchParams }) => {
  const at = Number(searchParams.get('at'))
  return buildLiveSnapshot(Number.isFinite(at) && at > 0 ? at : undefined)
})
