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 player_meta_exports = {};
__export(player_meta_exports, {
  buildPlayerMetaApiClientMethods: () => buildPlayerMetaApiClientMethods
});
module.exports = __toCommonJS(player_meta_exports);
function appendBooleanQuery(params, key, value) {
  if (value === true) {
    params.set(key, "true");
  }
}
function appendIntegerQuery(params, key, value) {
  if (Number.isInteger(value) && Number(value) >= 0) {
    params.set(key, String(value));
  }
}
function buildPlayerMetaApiClientMethods(input) {
  const { request, handleApiError } = input;
  return {
    async listAchievements(appId, options = {}) {
      const params = new URLSearchParams();
      appendBooleanQuery(params, "includeHiddenDefinitions", options.includeHiddenDefinitions);
      appendBooleanQuery(params, "includeRetired", options.includeRetired);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/achievements${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_achievements");
      }
      return response.body;
    },
    async getAchievement(appId, key, options = {}) {
      const params = new URLSearchParams();
      appendBooleanQuery(params, "includeHiddenDefinitions", options.includeHiddenDefinitions);
      appendBooleanQuery(params, "includeRetired", options.includeRetired);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/achievements/${encodeURIComponent(key)}${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "get_achievement");
      }
      return response.body;
    },
    async unlockAchievement(appId, key) {
      const response = await request({
        method: "POST",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/achievements/${encodeURIComponent(key)}/unlock`
      });
      if (response.status !== 200) {
        handleApiError(response, "unlock_achievement");
      }
      return response.body;
    },
    async setAchievementProgressAtLeast(appId, key, payload) {
      const response = await request({
        method: "PUT",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/achievements/${encodeURIComponent(key)}/progress`,
        body: payload
      });
      if (response.status !== 200) {
        handleApiError(response, "set_achievement_progress");
      }
      return response.body;
    },
    async listLeaderboards(appId, options = {}) {
      const params = new URLSearchParams();
      appendBooleanQuery(params, "includeRetired", options.includeRetired);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/leaderboards${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_leaderboards");
      }
      return response.body;
    },
    async getLeaderboard(appId, key, options = {}) {
      const params = new URLSearchParams();
      appendIntegerQuery(params, "top", options.top);
      appendIntegerQuery(params, "aroundMe", options.aroundMe);
      appendBooleanQuery(params, "includeRetired", options.includeRetired);
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/leaderboards/${encodeURIComponent(key)}${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "get_leaderboard");
      }
      return response.body;
    },
    async submitLeaderboardScore(appId, key, payload) {
      const response = await request({
        method: "POST",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/leaderboards/${encodeURIComponent(key)}/submissions`,
        body: payload
      });
      if (response.status !== 200) {
        handleApiError(response, "submit_leaderboard_score");
      }
      return response.body;
    },
    async fetchMyAchievements() {
      const response = await request({
        method: "GET",
        path: "/v1/me/achievements"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_my_achievements");
      }
      return response.body;
    },
    async fetchMyLeaderboards() {
      const response = await request({
        method: "GET",
        path: "/v1/me/leaderboards"
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_my_leaderboards");
      }
      return response.body;
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildPlayerMetaApiClientMethods
});
