import { NextRequest, NextResponse } from "next/server";
import { reorderTeamMembers } from "@/lib/db";
import { revalidatePath } from "next/cache";

export async function PUT(request: NextRequest) {
  const { ids } = await request.json() as { ids: number[] };

  if (!Array.isArray(ids) || ids.length === 0) {
    return NextResponse.json({ error: "ids array required" }, { status: 400 });
  }

  reorderTeamMembers(ids);
  revalidatePath("/");

  return NextResponse.json({ ok: true });
}
