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

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