import { NextResponse } from "next/server";
import { apiHandler, ApiError } from "@/lib/api";
import { reverseGeocode } from "@/lib/amap";

export const GET = apiHandler(async (req) => {
  const lat = req.nextUrl.searchParams.get("lat");
  const lng = req.nextUrl.searchParams.get("lng");

  if (!lat || !lng) throw new ApiError("lat and lng are required");

  const result = await reverseGeocode({ lat: Number(lat), lng: Number(lng) });
  return NextResponse.json(result);
});
