import { NextResponse } from "next/server";
import { autocompleteDhlAddress } from "../../../lib/shippingDhl";

// Proxies the checkout's address-autocomplete input through to Payload's
// DHL DataFactory endpoint — same reasoning as validate-dhl-postnumber's
// own route: tenant DHL credentials must never reach the browser.
export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const query = searchParams.get("query") ?? "";
  const suggestions = await autocompleteDhlAddress(query);
  return NextResponse.json({ ok: true, suggestions });
}
