import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { getAllQuizUsers, getAllAttempts } from "@/lib/user-store";

export async function GET() {
  const session = await getServerSession(authOptions);
  if (!session || (session.user as { role?: string }).role !== "admin") {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const users = await getAllQuizUsers();
  const attempts = await getAllAttempts();

  return NextResponse.json({ users, attempts });
}
