import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { getLiveFeed } from "@/lib/live";

/** Polled by the live screen every few seconds — updates appear without a page refresh. */
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
  const user = await getCurrentUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  const { id } = await params;
  const feed = await getLiveFeed(id);
  if (!feed) return NextResponse.json({ error: "Not found" }, { status: 404 });
  return NextResponse.json(feed, { headers: { "Cache-Control": "no-store" } });
}
