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

const BACKUP_URL = process.env.BACKUP_SERVICE_URL || "http://127.0.0.1:8083";

export async function POST(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params;
  try {
    const res = await fetch(`${BACKUP_URL}/destinations/${encodeURIComponent(id)}/test`, {
      method: "POST",
    });
    const data = await res.json();
    return NextResponse.json(data);
  } catch {
    return NextResponse.json(
      { error: "Backup service unavailable" },
      { status: 502 }
    );
  }
}
