import { NextResponse } from "next/server";
import { deletePlan } from "@/lib/services/propertyDeletion";

export async function POST(
  req: Request,
  context: { params: Promise<{ id: string }> }
) {
  const { id } = await context.params;
  const planId = Number(id);

  if (Number.isNaN(planId)) {
    return NextResponse.json({ error: "Invalid plan id" }, { status: 400 });
  }

  const { confirm } = await req.json();

  if (confirm !== true) {
    return NextResponse.json(
      { error: "Explicit confirmation required" },
      { status: 400 }
    );
  }

  await deletePlan(planId);

  return NextResponse.json({
    success: true,
    dryRun: true,
  });
}
