var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var payments_exports = {};
__export(payments_exports, {
  buildPaymentsApiClientMethods: () => buildPaymentsApiClientMethods
});
module.exports = __toCommonJS(payments_exports);
function buildPaymentsApiClientMethods(input) {
  const { request, handleApiError, buildIapQuery } = input;
  return {
    async fetchPublicCreditShop() {
      const response = await request({
        method: "GET",
        path: "/shop/public"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_public_shop");
      }
      return response.body;
    },
    async fetchCreditShop() {
      const response = await request({
        method: "GET",
        path: "/shop"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_shop");
      }
      return response.body;
    },
    async createCreditPackCheckoutSession(sku, requestBody) {
      const normalizedSku = sku.trim();
      if (!normalizedSku) {
        throw new Error("invalid_credit_pack_sku");
      }
      const response = await request({
        method: "POST",
        path: `/shop/credit-packs/${encodeURIComponent(normalizedSku)}/checkout-session`,
        ...requestBody ? { body: requestBody } : {}
      });
      if (response.status !== 200) {
        handleApiError(response, "create_credit_pack_checkout_session");
      }
      return response.body;
    },
    async fetchCreditPackCheckoutStatus(sessionId) {
      const normalizedSessionId = sessionId.trim();
      if (!normalizedSessionId) {
        throw new Error("invalid_checkout_session_id");
      }
      const response = await request({
        method: "GET",
        path: `/shop/credit-packs/checkout-session/${encodeURIComponent(normalizedSessionId)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_credit_pack_checkout_status");
      }
      return response.body;
    },
    async purchaseAsset(body) {
      const response = await request({
        method: "POST",
        path: "/purchase",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "purchase_asset");
      }
      return response.body;
    },
    async purchaseIap(body) {
      const response = await request({
        method: "POST",
        path: "/iap/purchase",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "purchase_iap");
      }
      return response.body;
    },
    async purchaseDevIap(appId, slot, body) {
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(appId))}/dev/players/${encodeURIComponent(String(slot))}/iap/purchase`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "purchase_dev_iap");
      }
      return response.body;
    },
    async fetchIapReceipts(params) {
      const query = buildIapQuery(params);
      const path = query ? `/iap/receipts?${query}` : "/iap/receipts";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_iap_receipts");
      }
      return response.body;
    },
    async cancelIapReceipt(receiptId) {
      const response = await request({
        method: "POST",
        path: `/iap/receipts/${encodeURIComponent(String(receiptId))}/cancel`
      });
      if (response.status !== 200) {
        handleApiError(response, "cancel_iap_receipt");
      }
      return response.body;
    },
    async fetchAppIapReceipts(params) {
      const query = buildIapQuery(params);
      const path = query ? `/app/iap/receipts?${query}` : "/app/iap/receipts";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_app_iap_receipts");
      }
      return response.body;
    },
    async consumeAppIapReceipt(receiptId) {
      const response = await request({
        method: "POST",
        path: `/app/iap/receipts/${encodeURIComponent(String(receiptId))}/consume`
      });
      if (response.status !== 200) {
        handleApiError(response, "consume_app_iap_receipt");
      }
      return response.body;
    },
    async grantAppIapReceipt(receiptId) {
      const response = await request({
        method: "POST",
        path: `/app/iap/receipts/${encodeURIComponent(String(receiptId))}/grant`
      });
      if (response.status !== 200) {
        handleApiError(response, "grant_app_iap_receipt");
      }
      return response.body;
    },
    async cancelAppIapReceipt(receiptId) {
      const response = await request({
        method: "POST",
        path: `/app/iap/receipts/${encodeURIComponent(String(receiptId))}/cancel`
      });
      if (response.status !== 200) {
        handleApiError(response, "cancel_app_iap_receipt");
      }
      return response.body;
    },
    async fetchCreditTransactions(options) {
      const params = new URLSearchParams();
      if (options?.limit !== void 0) {
        params.set("limit", String(options.limit));
      }
      if (options?.offset !== void 0) {
        params.set("offset", String(options.offset));
      }
      const query = params.toString();
      const path = query ? `/transactions?${query}` : "/transactions";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_credit_transactions");
      }
      return response.body;
    },
    async fetchBoostBalance() {
      const response = await request({
        method: "GET",
        path: "/boosts/balance"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_boost_balance");
      }
      return response.body;
    },
    async purchaseBoostPack(body) {
      const normalizedQuantity = body.quantity;
      if (normalizedQuantity !== void 0) {
        if (!Number.isInteger(normalizedQuantity) || normalizedQuantity <= 0) {
          throw new Error("invalid_boost_quantity");
        }
      }
      const response = await request({
        method: "POST",
        path: "/boosts/purchase",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "purchase_boost_pack");
      }
      return response.body;
    },
    async activateAppBoost(appId, body) {
      const normalizedAppId = Number(appId);
      if (!Number.isInteger(normalizedAppId) || normalizedAppId <= 0) {
        throw new Error("invalid_app_id");
      }
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/activate`,
        ...body ? { body } : {}
      });
      if (response.status !== 200) {
        handleApiError(response, "activate_app_boost");
      }
      return response.body;
    },
    async fetchAppBoostStatus(appId) {
      const normalizedAppId = Number(appId);
      if (!Number.isInteger(normalizedAppId) || normalizedAppId <= 0) {
        throw new Error("invalid_app_id");
      }
      const response = await request({
        method: "GET",
        path: `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/status`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_app_boost_status");
      }
      return response.body;
    },
    async fetchAppBoostHistory(appId, options) {
      const normalizedAppId = Number(appId);
      if (!Number.isInteger(normalizedAppId) || normalizedAppId <= 0) {
        throw new Error("invalid_app_id");
      }
      const params = new URLSearchParams();
      if (typeof options?.limit === "number") {
        if (!Number.isInteger(options.limit) || options.limit <= 0) {
          throw new Error("invalid_boost_history_limit");
        }
        params.set("limit", String(options.limit));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: query ? `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/history?${query}` : `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/history`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_app_boost_history");
      }
      return response.body;
    },
    async fetchAppBoostReport(appId, options) {
      const normalizedAppId = Number(appId);
      if (!Number.isInteger(normalizedAppId) || normalizedAppId <= 0) {
        throw new Error("invalid_app_id");
      }
      const params = new URLSearchParams();
      if (typeof options?.days === "number") {
        if (options.startDateUtc || options.endDateUtc) {
          throw new Error("invalid_boost_report_range");
        }
        params.set("days", String(options.days));
      }
      if (typeof options?.startDateUtc === "string") {
        params.set("startDateUtc", options.startDateUtc);
      }
      if (typeof options?.endDateUtc === "string") {
        params.set("endDateUtc", options.endDateUtc);
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: query ? `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/report?${query}` : `/apps/${encodeURIComponent(String(normalizedAppId))}/boosts/report`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_app_boost_report");
      }
      return response.body;
    },
    async fetchCreatorEarnings(options) {
      const params = new URLSearchParams();
      if (typeof options?.days === "number") {
        params.set("days", String(options.days));
      }
      if (typeof options?.appId === "number") {
        params.set("appId", String(options.appId));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: query ? `/creator/earnings?${query}` : "/creator/earnings"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_creator_earnings");
      }
      return response.body;
    },
    async loadInterstitialAd(body) {
      const response = await request({
        method: "POST",
        path: "/ads/interstitial/load",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "load_interstitial_ad");
      }
      return response.body;
    },
    async loadDevInterstitialAd(appId, slot, body) {
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(appId))}/dev/players/${encodeURIComponent(String(slot))}/ads/interstitial/load`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "load_dev_interstitial_ad");
      }
      return response.body;
    },
    async showInterstitialAd(body) {
      const response = await request({
        method: "POST",
        path: "/ads/interstitial/show",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "show_interstitial_ad");
      }
      return response.body;
    },
    async showDevInterstitialAd(appId, slot, body) {
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(appId))}/dev/players/${encodeURIComponent(String(slot))}/ads/interstitial/show`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "show_dev_interstitial_ad");
      }
      return response.body;
    },
    async loadRewardedAd(body) {
      const response = await request({
        method: "POST",
        path: "/ads/rewarded/load",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "load_rewarded_ad");
      }
      return response.body;
    },
    async loadDevRewardedAd(appId, slot, body) {
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(appId))}/dev/players/${encodeURIComponent(String(slot))}/ads/rewarded/load`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "load_dev_rewarded_ad");
      }
      return response.body;
    },
    async showRewardedAd(body) {
      const response = await request({
        method: "POST",
        path: "/ads/rewarded/show",
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "show_rewarded_ad");
      }
      return response.body;
    },
    async showDevRewardedAd(appId, slot, body) {
      const response = await request({
        method: "POST",
        path: `/apps/${encodeURIComponent(String(appId))}/dev/players/${encodeURIComponent(String(slot))}/ads/rewarded/show`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "show_dev_rewarded_ad");
      }
      return response.body;
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildPaymentsApiClientMethods
});
