import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
import { getApiUser } from "@/lib/apiAuth";
// GET /api/quiz/my-results
export async function GET(req: NextRequest) {
  const apiUser = await getApiUser(req);
  if (!apiUser) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const userId = apiUser.id;

  const submissions = await db.quizSubmission.findMany({
    where: { userId },
    include: {
      quiz: {
        include: { questions: { orderBy: { order: "asc" } } },
      },
    },
    orderBy: { submittedAt: "desc" },
  });

  return NextResponse.json(submissions);
}
