"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.OxyServicesPaymentMixin = OxyServicesPaymentMixin;
var _mixinHelpers = require("./mixinHelpers");
/**
 * Payment Methods Mixin
 * 
 * Provides methods for payment processing and management
 */

function OxyServicesPaymentMixin(Base) {
  return class extends Base {
    constructor(...args) {
      super(...args);
    }

    /**
     * Create a payment
     * @param data - Payment data
     * @returns Created payment object
     */
    async createPayment(data) {
      try {
        return await this.makeRequest('POST', '/api/payments', data, {
          cache: false
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get payment by ID
     * @param paymentId - The payment ID
     * @returns Payment object
     */
    async getPayment(paymentId) {
      try {
        return await this.makeRequest('GET', `/api/payments/${paymentId}`, undefined, {
          cache: true,
          cacheTTL: _mixinHelpers.CACHE_TIMES.LONG
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get user payments
     * @returns Array of user payments
     */
    async getUserPayments() {
      try {
        return await this.makeRequest('GET', '/api/payments/user', undefined, {
          cache: false // Don't cache user payments - always get fresh data
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get user subscription
     * @param userId - The user ID
     * @returns Subscription object
     */
    async getSubscription(userId) {
      try {
        return await this.makeRequest('GET', `/api/subscription/${userId}`, undefined, {
          cache: true,
          cacheTTL: _mixinHelpers.CACHE_TIMES.MEDIUM
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get current user's subscription
     * @returns Subscription object
     */
    async getCurrentUserSubscription() {
      try {
        const userId = this.getCurrentUserId();
        if (!userId) {
          throw new Error('User not authenticated');
        }
        return await this.getSubscription(userId);
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get user wallet
     * @param userId - The user ID
     * @returns Wallet object with balance
     */
    async getWallet(userId) {
      try {
        return await this.makeRequest('GET', `/api/wallet/${userId}`, undefined, {
          cache: true,
          cacheTTL: _mixinHelpers.CACHE_TIMES.SHORT // Cache wallet for short time as balance changes frequently
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get current user's wallet
     * @returns Wallet object with balance
     */
    async getCurrentUserWallet() {
      try {
        const userId = this.getCurrentUserId();
        if (!userId) {
          throw new Error('User not authenticated');
        }
        return await this.getWallet(userId);
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get wallet transaction history
     * @param userId - The user ID
     * @param options - Pagination options
     * @returns Transaction history
     */
    async getWalletTransactions(userId, options) {
      try {
        const params = new URLSearchParams();
        if (options?.limit) params.append('limit', options.limit.toString());
        if (options?.offset) params.append('offset', options.offset.toString());
        const queryString = params.toString();
        const url = `/api/wallet/transactions/${userId}${queryString ? `?${queryString}` : ''}`;
        return await this.makeRequest('GET', url, undefined, {
          cache: false // Don't cache transactions - always get fresh data
        });
      } catch (error) {
        throw this.handleError(error);
      }
    }

    /**
     * Get current user's wallet transaction history
     * @param options - Pagination options
     * @returns Transaction history
     */
    async getCurrentUserWalletTransactions(options) {
      try {
        const userId = this.getCurrentUserId();
        if (!userId) {
          throw new Error('User not authenticated');
        }
        return await this.getWalletTransactions(userId, options);
      } catch (error) {
        throw this.handleError(error);
      }
    }
  };
}
//# sourceMappingURL=OxyServices.payment.js.map