"use strict";
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/payments.ts
var payments_exports = {};
__export(payments_exports, {
  PaymentsModule: () => PaymentsModule
});
module.exports = __toCommonJS(payments_exports);

// src/types/token.ts
var SupportedToken = /* @__PURE__ */ ((SupportedToken2) => {
  SupportedToken2["USDT"] = "USDT";
  return SupportedToken2;
})(SupportedToken || {});
var TOKEN_ADDRESSES = {
  // [SupportedToken.USDC]: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyB7u6T',
  ["USDT" /* USDT */]: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
};
var TOKEN_DECIMALS = {
  // [SupportedToken.USDC]: 6, // USDC has 6 decimal places
  ["USDT" /* USDT */]: 6
  // USDT has 6 decimal places
};
var TokenUtils = class {
  /**
   * Get the SPL token address from a token enum
   */
  static getTokenAddress(token) {
    return TOKEN_ADDRESSES[token];
  }
  /**
   * Get token enum from SPL address
   */
  static getTokenFromAddress(address) {
    for (const [token, addr] of Object.entries(TOKEN_ADDRESSES)) {
      if (addr === address) {
        return token;
      }
    }
    return null;
  }
  /**
   * Get the number of decimal places for a given token
   */
  static getTokenDecimals(token) {
    return TOKEN_DECIMALS[token] || 6;
  }
  /**
   * Check if a token is supported
   */
  static isTokenSupported(token) {
    return Object.values(SupportedToken).includes(token);
  }
  /**
   * Get the default token (USDT)
   */
  static getDefaultToken() {
    return "USDT" /* USDT */;
  }
};

// src/modules/payments.ts
var PaymentsModule = class {
  constructor(client) {
    this.client = client;
  }
  // --- Product Methods ---
  async createProduct(payload) {
    const requestPayload = { ...payload };
    if (requestPayload.token && !requestPayload.splTokenAddress) {
      requestPayload.splTokenAddress = TokenUtils.getTokenAddress(requestPayload.token);
    }
    if (requestPayload.price) {
      const token = requestPayload.token || "USDT" /* USDT */;
      const decimals = TokenUtils.getTokenDecimals(token);
      const priceValue = typeof requestPayload.price === "string" ? parseFloat(requestPayload.price) : requestPayload.price;
      const priceInBaseUnits = Math.round(priceValue * 10 ** decimals);
      requestPayload.price = priceInBaseUnits.toString();
    }
    const response = await this.client.post("/v1/products", requestPayload);
    return response.data;
  }
  async getProduct(productId) {
    const response = await this.client.get(`/v1/products/${productId}`);
    return response.data;
  }
  async listProducts() {
    const response = await this.client.get("/v1/products");
    return response.data;
  }
  async updateProduct(productId, payload) {
    const requestPayload = { ...payload };
    if (requestPayload.token && !requestPayload.splTokenAddress) {
      requestPayload.splTokenAddress = TokenUtils.getTokenAddress(requestPayload.token);
    }
    const response = await this.client.put(
      `/v1/products/${productId}`,
      requestPayload
    );
    return response.data;
  }
  async deleteProduct(productId) {
    await this.client.delete(`/v1/products/${productId}`);
  }
  // --- Invoice Methods ---
  async createInvoice(payload) {
    const requestPayload = { ...payload };
    if ("token" in requestPayload && !("splTokenAddress" in requestPayload)) {
      requestPayload.splTokenAddress = TokenUtils.getTokenAddress(requestPayload.token);
    }
    const response = await this.client.post("/v1/invoices", requestPayload);
    return response.data;
  }
  async getInvoice(invoiceId) {
    const response = await this.client.get(`/v1/invoices/${invoiceId}`);
    return response.data;
  }
  async listInvoices() {
    const response = await this.client.get("/v1/invoices");
    return response.data;
  }
  async deleteInvoice(invoiceId) {
    await this.client.delete(`/v1/invoices/${invoiceId}`);
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PaymentsModule
});
