import { CurrencyType as s, ItemType as m } from "./accelbyte-widgets185.mjs";
import { RegionDataItemHelper as a } from "./accelbyte-widgets388.mjs";
class P {
  static entitlementConstraintUnavailableForPurchase(t) {
    return t.maxAllowedPurchase <= 0;
  }
  static purchaseUnavailable(t) {
    return t ? this.entitlementConstraintUnavailableForPurchase(t.entitlementConstraint) : !1;
  }
  static getMaxPurchaseByWallet(t, n) {
    switch (t.currencyType) {
      case s.enum.REAL:
        return 1 / 0;
      case s.enum.VIRTUAL:
        return n ? Math.floor(n.balance / t.finalPrice) : 0;
      default:
        return 0;
    }
  }
  static itemIsFree(t) {
    return !!t.regionData;
  }
  static makePaymentOption(t, n) {
    const r = n.get(t.currencyCode);
    if (!r)
      return null;
    const i = r.currencyType, e = r.currencySymbol || r.currencyCode, c = this.calculateIntegerPrice(a.getFinalPrice(t), r), u = this.calculateIntegerPrice(t.price || 0, r), l = r.decimals;
    return {
      currencyType: i,
      currencySymbol: e,
      finalPrice: c,
      originalPrice: u,
      decimals: l,
      regionData: t
    };
  }
  static makePaymentOptionList(t, n) {
    if (!n)
      return [];
    const r = t.filter(
      (e) => a.isPurchasable(e) && a.hasMatchingCurrencyInMap(e, n)
    ).map((e) => this.makePaymentOption(e, n)).filter((e) => e !== null);
    return [
      ...r.filter((e) => (e == null ? void 0 : e.currencyType) === s.enum.REAL),
      ...r.filter((e) => (e == null ? void 0 : e.currencyType) === s.enum.VIRTUAL)
    ];
  }
  static makeWalletConstraint(t, n) {
    const r = n.get(t.regionData.currencyCode) || null;
    return {
      wallet: r,
      maxPurchase: this.getMaxPurchaseByWallet(t, r)
    };
  }
  static makePaymentOptionWithExpiryDiscount(t, n) {
    return this.makePaymentOptionList(t, n).filter(
      (r) => a.isDiscountExpirable(r.regionData) && a.isDiscounted(r.regionData)
    );
  }
  static convertMaxCountValue(t) {
    return t === void 0 || t === -1 ? 1 / 0 : Math.max(t, 0);
  }
  static convertAvailableCountValue(t) {
    return t === void 0 || t === -1 ? 1 / 0 : Math.max(t, 0);
  }
  static getMaxEntitlementsAllowed(t) {
    switch (t.itemType) {
      case m.enum.APP:
        return 1;
      default:
        return Math.min(this.convertMaxCountValue(t.maxCount), this.convertMaxCountValue(t.maxCountPerUser));
    }
  }
  static makePaymentEntitlementConstraint(t) {
    return {
      maxAllowedPurchase: this.convertAvailableCountValue(t.userPurchaseLimit)
    };
  }
  static makePurchaseConstraint(t, n, r, i) {
    return {
      paymentConstraints: this.makePaymentOptionList(t.regionData || [], r).map((e) => ({
        paymentOption: e,
        walletConstraint: this.makeWalletConstraint(e, i)
      })),
      entitlementConstraint: this.makePaymentEntitlementConstraint(n)
    };
  }
  static calculateIntegerPrice(t, n) {
    return t === null ? 0 : t / 10 ** n.decimals;
  }
}
export {
  P as PurchaseHelper
};
