import { NextResponse } from "next/server";
import { getPollById } from "@/lib/data";
import type { Poll } from "@/types";

interface RouteParams {
  params: Promise<{ id: string }>;
}

// STAP 3: GET /api/polls/[id] — enkele poll ophalen
// (Dit bestand is COMPLEET van Les 5. Dit is stap 3 van Les 5.)

export async function GET(
  request: Request,
  { params }: RouteParams
): Promise<NextResponse> {
  const { id } = await params;
  const poll = getPollById(id);

  if (!poll) {
    return NextResponse.json(
      { error: "Poll niet gevonden" },
      { status: 404 }
    );
  }

  return NextResponse.json<Poll>(poll);
}
