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

type Params = { params: Promise<{ id: string }> };

export async function GET(_request: NextRequest, { params }: Params) {
  const { id } = await params;
  const member = getTeamMember(Number(id));
  if (!member) {
    return NextResponse.json({ error: "Not found" }, { status: 404 });
  }
  return NextResponse.json(member);
}

export async function PUT(request: NextRequest, { params }: Params) {
  const { id } = await params;
  const data = await request.json();
  updateTeamMember(Number(id), data);
  revalidatePath("/");
  return NextResponse.json({ ok: true });
}

export async function DELETE(_request: NextRequest, { params }: Params) {
  const { id } = await params;
  deleteTeamMember(Number(id));
  revalidatePath("/");
  return NextResponse.json({ ok: true });
}
