import { NextRequest, NextResponse } from "next/server";

const BRIDGE_URL = process.env.IMESSAGE_BRIDGE_URL || "http://127.0.0.1:8082";

export async function DELETE(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params;
  try {
    const res = await fetch(`${BRIDGE_URL}/contacts/${encodeURIComponent(id)}`, {
      method: "DELETE",
    });
    if (!res.ok) {
      return NextResponse.json({ error: "Contact not found" }, { status: 404 });
    }
    const data = await res.json();
    return NextResponse.json(data);
  } catch {
    return NextResponse.json(
      { error: "Bridge service unavailable" },
      { status: 502 }
    );
  }
}
