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

export const GET = apiHandler(async (req) => {
  const keywords = req.nextUrl.searchParams.get("keywords")?.trim();
  if (!keywords) throw new ApiError("keywords 不能为空");

  const city = req.nextUrl.searchParams.get("city")?.trim();
  const types = req.nextUrl.searchParams.get("types")?.trim();

  const results = await searchPlaceText({ keywords, city: city || undefined, types: types || undefined });
  return NextResponse.json(results);
});
