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);

// src/modules/Payment/utils.ts
var utils_exports = {};
__export(utils_exports, {
  formatWalletPassList2PreparePayments: () => formatWalletPassList2PreparePayments,
  getAvailableMaxAmount: () => getAvailableMaxAmount,
  sortUserIdentificationCodeList: () => sortUserIdentificationCodeList
});
module.exports = __toCommonJS(utils_exports);
var getAvailableMaxAmount = (data) => {
  if (typeof data._available_max_amount === "number") {
    return data._available_max_amount;
  }
  return data.tag !== "point_card" ? data.available_max_amount : data == null ? void 0 : data.recommended_usage_amount;
};
var formatWalletPassList2PreparePayments = (list) => {
  const formatted = (list || []).map((item) => {
    return {
      voucher_id: item.id || 0,
      amount: Number(item.edit_current_amount || getAvailableMaxAmount(item)) || 0,
      tag: item.tag || "",
      wallet_pass_usage_unit: item.wallet_pass_usage_unit || {},
      wallet_pass_use_value: item.wallet_pass_use_value || void 0
    };
  });
  return formatted;
};
var sortUserIdentificationCodeList = (list) => {
  if (!Array.isArray(list) || list.length === 0) {
    return list;
  }
  const middlePriorityErrorCodes = ["500601", "500602"];
  return list.sort((a, b) => {
    const getPriority = (item) => {
      var _a;
      const errorCode = (_a = item.unified_error_code) == null ? void 0 : _a.toString();
      const availableStatus = item.unified_available_status;
      if (errorCode && middlePriorityErrorCodes.includes(errorCode))
        return 2;
      if (availableStatus === 0)
        return 3;
      if (availableStatus === 1)
        return 1;
      return 0;
    };
    const aPriority = getPriority(a);
    const bPriority = getPriority(b);
    return aPriority - bPriority;
  });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatWalletPassList2PreparePayments,
  getAvailableMaxAmount,
  sortUserIdentificationCodeList
});
