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 admin_exports = {};
__export(admin_exports, {
  buildAdminApiClientMethods: () => buildAdminApiClientMethods
});
module.exports = __toCommonJS(admin_exports);
var import_request = require("../core/request.js");
function buildAdminPaymentsQueryString(options) {
  const params = new URLSearchParams();
  if (options?.provider) {
    params.set("provider", options.provider);
  }
  if (options?.status) {
    const statuses = Array.isArray(options.status) ? options.status : [options.status];
    params.set("status", statuses.join(","));
  }
  if (typeof options?.userId === "number") {
    params.set("userId", String(options.userId));
  }
  if (options?.creditPackSku) {
    params.set("creditPackSku", options.creditPackSku);
  }
  if (options?.from) {
    params.set("from", options.from instanceof Date ? options.from.toISOString() : options.from);
  }
  if (options?.to) {
    params.set("to", options.to instanceof Date ? options.to.toISOString() : options.to);
  }
  if (typeof options?.limit === "number") {
    params.set("limit", String(options.limit));
  }
  if (typeof options?.offset === "number") {
    params.set("offset", String(options.offset));
  }
  return params.toString();
}
function buildAdminAppVersionReviewsQueryString(options) {
  const params = new URLSearchParams();
  if (options?.state) {
    params.set("state", options.state);
  }
  if (typeof options?.limit === "number") {
    params.set("limit", String(options.limit));
  }
  if (typeof options?.offset === "number") {
    params.set("offset", String(options.offset));
  }
  return params.toString();
}
async function buildAuthorizedHeaders(getClientHeaders, resolveToken) {
  const headers = new Headers();
  for (const [key, value] of Object.entries(getClientHeaders())) {
    headers.set(key, value);
  }
  const token = await resolveToken();
  if (token) {
    headers.set("authorization", `Bearer ${token}`);
  }
  return headers;
}
function buildAdminApiClientMethods(input) {
  const { request, handleApiError, fetchImpl, includeBrowserCredentials, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders } = input;
  return {
    async fetchUsers() {
      const response = await request({
        method: "GET",
        path: "/admin/users"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_users");
      }
      return response.body;
    },
    async createUser(userRequest) {
      const response = await request({
        method: "POST",
        path: "/admin/users",
        body: userRequest
      });
      if (response.status !== 201 && response.status !== 200) {
        handleApiError(response, "create_user");
      }
      return response.body;
    },
    async batchCreateUsersFromCsv(formData) {
      const base = resolveBaseUrl();
      const headers = new Headers();
      for (const [key, value] of Object.entries(getClientHeaders())) {
        headers.set(key, value);
      }
      const token = await resolveToken();
      if (token) {
        headers.set("authorization", `Bearer ${token}`);
      }
      const path = "/admin/users/batch-create";
      const response = await fetchImpl(resolveUrl(base, path), {
        method: "POST",
        headers,
        body: formData,
        ...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
      });
      const parsed = await parseResponseBody(response);
      const apiResponse = { status: response.status, body: parsed, headers: response.headers };
      if (response.status !== 200 && response.status !== 201) {
        handleApiError(apiResponse, "batch_create_users");
      }
      return parsed;
    },
    async fetchAdminUser(userId) {
      const response = await request({
        method: "GET",
        path: `/admin/users/${encodeURIComponent(String(userId))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_user");
      }
      return response.body;
    },
    async updateAdminUser(userId, updateRequest) {
      const response = await request({
        method: "PATCH",
        path: `/admin/users/${encodeURIComponent(String(userId))}`,
        body: updateRequest
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_user");
      }
      return response.body;
    },
    async deleteAdminUser(userId) {
      const response = await request({
        method: "DELETE",
        path: `/admin/users/${encodeURIComponent(String(userId))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_admin_user");
      }
      return response.body;
    },
    async fetchAdminApps() {
      const response = await request({
        method: "GET",
        path: "/admin/apps"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_apps");
      }
      return response.body;
    },
    async updateAdminApp(id, updateRequest) {
      const response = await request({
        method: "PATCH",
        path: `/admin/apps/${encodeURIComponent(String(id))}`,
        body: updateRequest
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_app");
      }
      return response.body;
    },
    async deleteAdminApp(id) {
      const response = await request({
        method: "DELETE",
        path: `/admin/apps/${encodeURIComponent(String(id))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_admin_app");
      }
      return response.body;
    },
    async fetchAdminGameCollections() {
      const response = await request({
        method: "GET",
        path: "/admin/game-collections"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_game_collections");
      }
      return response.body;
    },
    async createAdminGameCollection(requestBody) {
      const response = await request({
        method: "POST",
        path: "/admin/game-collections",
        body: requestBody
      });
      if (response.status !== 201 && response.status !== 200) {
        handleApiError(response, "create_admin_game_collection");
      }
      return response.body;
    },
    async fetchAdminGameCollection(id) {
      const response = await request({
        method: "GET",
        path: `/admin/game-collections/${encodeURIComponent(String(id))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_game_collection");
      }
      return response.body;
    },
    async updateAdminGameCollection(id, requestBody) {
      const response = await request({
        method: "PATCH",
        path: `/admin/game-collections/${encodeURIComponent(String(id))}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_game_collection");
      }
      return response.body;
    },
    async replaceAdminGameCollectionGames(id, requestBody) {
      const response = await request({
        method: "PUT",
        path: `/admin/game-collections/${encodeURIComponent(String(id))}/games`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "replace_admin_game_collection_games");
      }
      return response.body;
    },
    async searchAdminGameCollectionCandidates(options) {
      const params = new URLSearchParams();
      params.set("q", options.q);
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      const response = await request({
        method: "GET",
        path: `/admin/game-collections/candidates?${params.toString()}`
      });
      if (response.status !== 200) {
        handleApiError(response, "search_admin_game_collection_candidates");
      }
      return response.body;
    },
    async uploadAdminGameCollectionIcon(id, formData) {
      const base = resolveBaseUrl();
      const headers = await buildAuthorizedHeaders(getClientHeaders, resolveToken);
      const path = `/admin/game-collections/${encodeURIComponent(String(id))}/icon`;
      const response = await fetchImpl(resolveUrl(base, path), {
        method: "POST",
        headers,
        body: formData,
        ...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
      });
      const parsed = await parseResponseBody(response);
      const apiResponse = { status: response.status, body: parsed, headers: response.headers };
      if (response.status !== 200) {
        handleApiError(apiResponse, "upload_admin_game_collection_icon");
      }
      return parsed;
    },
    async deleteAdminGameCollection(id) {
      const response = await request({
        method: "DELETE",
        path: `/admin/game-collections/${encodeURIComponent(String(id))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_admin_game_collection");
      }
      return response.body;
    },
    async fetchAdminAppVersionReviews(options) {
      const query = buildAdminAppVersionReviewsQueryString(options);
      const response = await request({
        method: "GET",
        path: "/admin/app-version-reviews" + (query ? `?${query}` : "")
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_app_version_reviews");
      }
      return response.body;
    },
    async claimNextAdminAppVersionReview() {
      const response = await request({
        method: "POST",
        path: "/admin/app-version-reviews/claim-next"
      });
      if (response.status !== 200) {
        handleApiError(response, "claim_next_admin_app_version_review");
      }
      return response.body;
    },
    async updateAdminAppVersionReview(versionId, requestBody) {
      const response = await request({
        method: "PATCH",
        path: `/admin/app-version-reviews/${encodeURIComponent(String(versionId))}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_app_version_review");
      }
      return response.body;
    },
    async fetchAdminAppPlayerMeta(appId) {
      const response = await request({
        method: "GET",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_app_player_meta");
      }
      return response.body;
    },
    async fetchAdminAppPlayerMetaUser(appId, userId) {
      const response = await request({
        method: "GET",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta/users/${encodeURIComponent(String(userId))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_app_player_meta_user");
      }
      return response.body;
    },
    async retireAdminAchievement(appId, key) {
      const response = await request({
        method: "POST",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta/achievements/${encodeURIComponent(key)}/retire`
      });
      if (response.status !== 200) {
        handleApiError(response, "retire_admin_achievement");
      }
      return response.body;
    },
    async retireAdminLeaderboard(appId, key) {
      const response = await request({
        method: "POST",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta/leaderboards/${encodeURIComponent(key)}/retire`
      });
      if (response.status !== 200) {
        handleApiError(response, "retire_admin_leaderboard");
      }
      return response.body;
    },
    async mutateAdminAchievementState(appId, userId, key, body) {
      const response = await request({
        method: "POST",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta/users/${encodeURIComponent(String(userId))}/achievements/${encodeURIComponent(key)}`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "mutate_admin_achievement_state");
      }
      return response.body;
    },
    async mutateAdminLeaderboardScore(appId, userId, key, body) {
      const response = await request({
        method: "POST",
        path: `/admin/apps/${encodeURIComponent(String(appId))}/player-meta/users/${encodeURIComponent(String(userId))}/leaderboards/${encodeURIComponent(key)}`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "mutate_admin_leaderboard_score");
      }
      return response.body;
    },
    async fetchAdminCreditPacks() {
      const response = await request({
        method: "GET",
        path: "/admin/credit-packs"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_credit_packs");
      }
      return response.body;
    },
    async createAdminCreditPack(body) {
      const response = await request({
        method: "POST",
        path: "/admin/credit-packs",
        body
      });
      if (response.status !== 201) {
        handleApiError(response, "create_admin_credit_pack");
      }
      return response.body;
    },
    async updateAdminCreditPack(sku, body) {
      const response = await request({
        method: "PATCH",
        path: `/admin/credit-packs/${encodeURIComponent(sku)}`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "update_admin_credit_pack");
      }
      return response.body;
    },
    async deleteAdminCreditPack(sku) {
      const response = await request({
        method: "DELETE",
        path: `/admin/credit-packs/${encodeURIComponent(sku)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_admin_credit_pack");
      }
      return response.body;
    },
    async syncAdminCreditPacksStripe() {
      const response = await request({
        method: "POST",
        path: "/admin/credit-packs/sync-stripe"
      });
      if (response.status !== 200) {
        handleApiError(response, "sync_admin_credit_packs_stripe");
      }
      return response.body;
    },
    async fetchAdminPayments(options) {
      const query = buildAdminPaymentsQueryString(options);
      const path = query ? `/admin/payments?${query}` : "/admin/payments";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_payments");
      }
      return response.body;
    },
    async fetchAdminPayment(paymentId) {
      const response = await request({
        method: "GET",
        path: `/admin/payments/${encodeURIComponent(String(paymentId))}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_payment");
      }
      return response.body;
    },
    async refundAdminPayment(paymentId, body) {
      const response = await request({
        method: "POST",
        path: `/admin/payments/${encodeURIComponent(String(paymentId))}/refund`,
        body
      });
      if (response.status !== 200) {
        handleApiError(response, "refund_admin_payment");
      }
      return response.body;
    },
    async reconcileAdminPayment(paymentId) {
      const response = await request({
        method: "POST",
        path: `/admin/payments/${encodeURIComponent(String(paymentId))}/reconcile`
      });
      if (response.status !== 200) {
        handleApiError(response, "reconcile_admin_payment");
      }
      return response.body;
    },
    async fetchAdminCreditTransactions(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 ? `/admin/credit-transactions?${query}` : "/admin/credit-transactions";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_credit_transactions");
      }
      return response.body;
    },
    async fetchAdminAiGenerations(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 ? `/admin/ai-generations?${query}` : "/admin/ai-generations";
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_ai_generations");
      }
      return response.body;
    },
    async fetchAdminAiGeneration(id) {
      const response = await request({
        method: "GET",
        path: `/admin/ai-generations/${id}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_admin_ai_generation");
      }
      return response.body;
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildAdminApiClientMethods
});
