import { getCatalogDetails, type CatalogKind } from "@/lib/catalog";

type Params = {
  kind: string;
  id: string;
};

function isDetailKind(kind: string): kind is Exclude<CatalogKind, "music"> {
  return kind === "television" || kind === "movies";
}

export async function GET(_request: Request, context: { params: Promise<Params> }) {
  const { kind, id } = await context.params;

  if (!isDetailKind(kind)) {
    return Response.json({ error: "Unsupported catalog kind" }, { status: 400 });
  }

  try {
    const details = await getCatalogDetails(kind, id);
    return Response.json(details);
  } catch (error) {
    console.error("Failed to load catalog details", error);
    return Response.json({ error: "Failed to load catalog details" }, { status: 502 });
  }
}
