import { NextResponse } from "next/server";
import { getSessionUser } from "@/lib/auth/get-session-user";
import { deleteProjectSocialAccount } from "@/lib/storage/social-accounts";

export async function DELETE(
  request: Request,
  { params }: { params: Promise<{ projectId: string }> },
) {
  const user = await getSessionUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const { projectId } = await params;
  const platform = new URL(request.url).searchParams.get("platform");
  if (!platform) {
    return NextResponse.json({ error: "platform query param is required" }, { status: 400 });
  }

  await deleteProjectSocialAccount(user.id, projectId, platform);
  return NextResponse.json({ success: true });
}
