import { NextResponse } from "next/server";
import { db } from "@/lib/db";

export async function GET() {
  const teams = await db.team.findMany({
    orderBy: { totalPoints: "desc" },
    include: { user: { select: { name: true, email: true } } },
    take: 50,
  });

  return NextResponse.json(
    teams.map((t, i) => ({
      rank: i + 1,
      teamName: t.name,
      userName: t.user.name ?? t.user.email,
      totalPoints: t.totalPoints,
      budget: t.budget,
    }))
  );
}
