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

export async function loadCommercialNotifications(): Promise<
  AdapterResult<CommercialNotification[]>
> {
  const res = await commercialGet<unknown>("/api/v1/commercial/notifications");
  if (!res.ok) {
    return failResult(res.availability, res.message || "اعلان‌ها در دسترس نیست", []);
  }
  const items = extractItems<CommercialNotification>(res.data, ["items", "notifications"]);
  return listResult(items, "commercial.notifications", "اعلانی نیست");
}
