import type { AdapterResult, RecommendationResult } from "../types";
import { commercialPost, failResult } from "./http";

export type RecommendationAnswers = Record<string, unknown>;

const EMPTY: RecommendationResult = {
  recommended_products: [],
  recommended_bundles: [],
  recommended_capabilities: [],
  recommended_pricing: [],
  rule_trace: [],
};

export async function requestRecommendations(
  answers: RecommendationAnswers
): Promise<AdapterResult<RecommendationResult>> {
  const result = await commercialPost<RecommendationResult>("/api/v1/commercial/recommendations", {
    answers,
    version: "recommendation.v1",
  });
  if (!result.ok) {
    return failResult(result.availability, result.message || "موتور پیشنهاد در دسترس نیست", EMPTY);
  }
  return { availability: "ready", data: result.data, source: "commercial.recommendations" };
}
