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

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