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, {
  ADMIN_ACHIEVEMENT_MUTATION_ACTION_VALUES: () => ADMIN_ACHIEVEMENT_MUTATION_ACTION_VALUES,
  ADMIN_LEADERBOARD_MUTATION_ACTION_VALUES: () => ADMIN_LEADERBOARD_MUTATION_ACTION_VALUES,
  APP_ACHIEVEMENT_KIND_VALUES: () => APP_ACHIEVEMENT_KIND_VALUES,
  APP_LEADERBOARD_SCORE_TYPE_VALUES: () => APP_LEADERBOARD_SCORE_TYPE_VALUES,
  APP_LEADERBOARD_SORT_VALUES: () => APP_LEADERBOARD_SORT_VALUES,
  PLAYER_META_DEFINITION_STATUS_VALUES: () => PLAYER_META_DEFINITION_STATUS_VALUES,
  PLAYER_META_ERROR_CODE_VALUES: () => PLAYER_META_ERROR_CODE_VALUES,
  PLAYER_META_KEY_REGEX: () => PLAYER_META_KEY_REGEX,
  computeAchievementProgressPercent: () => computeAchievementProgressPercent,
  formatLeaderboardScore: () => formatLeaderboardScore,
  isPlayerMetaKey: () => isPlayerMetaKey,
  isSafeNonNegativeInteger: () => isSafeNonNegativeInteger,
  isSafePositiveInteger: () => isSafePositiveInteger,
  isValidLeaderboardDefinitionCombination: () => isValidLeaderboardDefinitionCombination,
  parseAdminAchievementMutationAction: () => parseAdminAchievementMutationAction,
  parseAdminLeaderboardMutationAction: () => parseAdminLeaderboardMutationAction,
  parseAppAchievementKind: () => parseAppAchievementKind,
  parseAppLeaderboardScoreType: () => parseAppLeaderboardScoreType,
  parseAppLeaderboardSort: () => parseAppLeaderboardSort,
  parsePlayerMetaDefinitionStatus: () => parsePlayerMetaDefinitionStatus
});
module.exports = __toCommonJS(player_meta_exports);
const PLAYER_META_KEY_REGEX = /^[a-z][a-z0-9_.-]{2,63}$/;
const PLAYER_META_DEFINITION_STATUS_VALUES = ["ACTIVE", "RETIRED"];
const APP_ACHIEVEMENT_KIND_VALUES = ["STANDARD", "INCREMENTAL"];
const APP_LEADERBOARD_SCORE_TYPE_VALUES = ["INTEGER", "TIME_MS"];
const APP_LEADERBOARD_SORT_VALUES = ["DESC", "ASC"];
const PLAYER_META_ERROR_CODE_VALUES = [
  "E_AUTH_REQUIRED",
  "E_RUNTIME_AUTH_REQUIRED",
  "E_META_NOT_FOUND",
  "E_META_RETIRED",
  "E_META_INVALID_KEY",
  "E_META_INVALID_DEFINITION",
  "E_INVALID_ARGUMENT",
  "E_SCORE_INVALID",
  "E_PROGRESS_INVALID",
  "E_FEATURE_KIND_MISMATCH",
  "E_RATE_LIMITED"
];
const ADMIN_ACHIEVEMENT_MUTATION_ACTION_VALUES = ["grant", "revoke", "reset"];
const ADMIN_LEADERBOARD_MUTATION_ACTION_VALUES = ["reset", "remove"];
function isPlayerMetaKey(value) {
  return typeof value === "string" && PLAYER_META_KEY_REGEX.test(value.trim());
}
function parsePlayerMetaDefinitionStatus(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toUpperCase();
  return PLAYER_META_DEFINITION_STATUS_VALUES.includes(normalized) ? normalized : null;
}
function parseAppAchievementKind(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toUpperCase();
  return APP_ACHIEVEMENT_KIND_VALUES.includes(normalized) ? normalized : null;
}
function parseAppLeaderboardScoreType(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toUpperCase();
  return APP_LEADERBOARD_SCORE_TYPE_VALUES.includes(normalized) ? normalized : null;
}
function parseAppLeaderboardSort(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toUpperCase();
  return APP_LEADERBOARD_SORT_VALUES.includes(normalized) ? normalized : null;
}
function parseAdminAchievementMutationAction(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toLowerCase();
  return ADMIN_ACHIEVEMENT_MUTATION_ACTION_VALUES.includes(normalized) ? normalized : null;
}
function parseAdminLeaderboardMutationAction(value) {
  if (typeof value !== "string") {
    return null;
  }
  const normalized = value.trim().toLowerCase();
  return ADMIN_LEADERBOARD_MUTATION_ACTION_VALUES.includes(normalized) ? normalized : null;
}
function isSafeNonNegativeInteger(value) {
  return Number.isSafeInteger(value) && Number(value) >= 0;
}
function isSafePositiveInteger(value) {
  return Number.isSafeInteger(value) && Number(value) > 0;
}
function isValidLeaderboardDefinitionCombination(scoreType, sort) {
  return scoreType === "INTEGER" && sort === "DESC" || scoreType === "TIME_MS" && sort === "ASC";
}
function computeAchievementProgressPercent(progress, maxProgress) {
  if (!Number.isSafeInteger(progress) || progress < 0) {
    throw new Error("invalid_progress_value");
  }
  if (!Number.isSafeInteger(maxProgress) || maxProgress <= 0) {
    throw new Error("invalid_max_progress_value");
  }
  const clamped = Math.min(progress, maxProgress);
  return Math.floor(clamped / maxProgress * 100);
}
function formatLeaderboardScore(score, scoreType, unitLabel) {
  if (!Number.isSafeInteger(score) || score < 0) {
    throw new Error("invalid_score_value");
  }
  if (scoreType === "TIME_MS") {
    if (score <= 0) {
      throw new Error("invalid_time_score_value");
    }
    const totalMilliseconds = score;
    const minutes = Math.floor(totalMilliseconds / 6e4);
    const seconds = Math.floor(totalMilliseconds % 6e4 / 1e3);
    const milliseconds = totalMilliseconds % 1e3;
    return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
  }
  const formatted = new Intl.NumberFormat("en-US").format(score);
  return unitLabel && unitLabel.trim().length > 0 ? `${formatted} ${unitLabel.trim()}` : formatted;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ADMIN_ACHIEVEMENT_MUTATION_ACTION_VALUES,
  ADMIN_LEADERBOARD_MUTATION_ACTION_VALUES,
  APP_ACHIEVEMENT_KIND_VALUES,
  APP_LEADERBOARD_SCORE_TYPE_VALUES,
  APP_LEADERBOARD_SORT_VALUES,
  PLAYER_META_DEFINITION_STATUS_VALUES,
  PLAYER_META_ERROR_CODE_VALUES,
  PLAYER_META_KEY_REGEX,
  computeAchievementProgressPercent,
  formatLeaderboardScore,
  isPlayerMetaKey,
  isSafeNonNegativeInteger,
  isSafePositiveInteger,
  isValidLeaderboardDefinitionCombination,
  parseAdminAchievementMutationAction,
  parseAdminLeaderboardMutationAction,
  parseAppAchievementKind,
  parseAppLeaderboardScoreType,
  parseAppLeaderboardSort,
  parsePlayerMetaDefinitionStatus
});
