import type { AdapterResult, CommercialPricingItem } from "../types";
import { commercialGet, extractItems, failResult, listResult } from "./http";

/** Pricing catalog only — never invent amounts. */
export async function loadCommercialPricing(): Promise<AdapterResult<CommercialPricingItem[]>> {
  const res = await commercialGet<unknown>("/api/v1/commercial/pricing");
  if (!res.ok) {
    return failResult(res.availability, res.message || "کاتالوگ قیمت‌گذاری در دسترس نیست", []);
  }
  const items = extractItems<CommercialPricingItem>(res.data, ["items", "pricing"]);
  return listResult(items, "commercial.pricing", "آیتم قیمتی ثبت نشده است");
}
