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

export default defineEventHandler(async (event) => {
  await requireUser(event);
  const query = getQuery(event);
  const limit = Math.min(Number(query.limit) || 20, 50);

  const db = usePrisma();
  const scores = await db.gameScore.findMany({
    orderBy: [{ points: "desc" }, { wins: "desc" }],
    take: limit,
  });

  return scores;
});
