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

export async function POST(_: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const session = await getServerSession(authOptions);
  if (!session || (session.user as any).role !== "ADMIN")
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  // غیرفعال کردن همه
  await db.gameweek.updateMany({ data: { isActive: false } });
  // فعال کردن این هفته
  const gw = await db.gameweek.update({ where: { id }, data: { isActive: true } });
  return NextResponse.json(gw);
}
