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

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