import { searchPriceOffersViaN8n } from "@/src/lib/price-search/n8n";
import type { PriceSearchRequest, PriceSearchResponse } from "@/src/types/priceSearch";

export async function searchPriceOffers(
  input: PriceSearchRequest,
  meta?: { userId?: string; userName?: string },
): Promise<PriceSearchResponse> {
  const backend = (process.env.PRICE_SEARCH_BACKEND ?? "n8n").toLowerCase();

  if (backend === "n8n") {
    return searchPriceOffersViaN8n(input, meta);
  }

  throw new Error(`Backend ricerca prezzi non supportato: ${backend}`);
}
