import { NextResponse } from "next/server";
import { db } from "@/lib/db";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";

// GET /api/golden-cards - get current user's golden cards
export async function GET() {
  const session = await getServerSession(authOptions);
  if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const userId = (session.user as any).id;

  const cards = await db.goldenCard.findMany({
    where: { userId },
    include: {
      player: { include: { country: true } },
    },
    orderBy: { acquiredDate: "desc" },
  });

  return NextResponse.json(cards);
}
