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

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