import { usePrisma } from "../../../utils/prisma";

export default defineEventHandler(async (event) => {
  const user = await requireUser(event);
  const id = getRouterParam(event, "id");
  if (!id) throw createError({ statusCode: 400, message: "id fehlt" });

  const db = usePrisma();
  const challenge = await db.gameChallenge.findUnique({ where: { id } });

  if (!challenge) {
    throw createError({ statusCode: 404, message: "Challenge nicht gefunden" });
  }

  return challenge;
});
