import { NextRequest, NextResponse } from "next/server";
import { getParticipantBalances } from "@/lib/queries";
import { getCurrentUser } from "@/lib/auth";

export async function GET(req: NextRequest) {
  const user = await getCurrentUser(req);
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const tagParam = req.nextUrl.searchParams.get("tag_ids");
  const tagIds = tagParam ? tagParam.split(",").map(Number).filter(Boolean) : undefined;
  const balances = await getParticipantBalances(user.id, tagIds);
  return NextResponse.json(balances);
}
