import {
  TokenUtils
} from "./chunk-EE7I5JHK.mjs";

// 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}`);
  }
};

export {
  PaymentsModule
};
