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

export async function loadCommercialCapabilities(): Promise<AdapterResult<CommercialCapability[]>> {
  const res = await commercialGet<unknown>("/api/v1/commercial/capabilities");
  if (!res.ok) {
    return failResult(res.availability, res.message || "رجیستری قابلیت در دسترس نیست", []);
  }
  const items = extractItems<CommercialCapability>(res.data, ["items", "capabilities"]);
  return listResult(items, "commercial.capabilities", "قابلیتی ثبت نشده است");
}
