import {
  ObjectSubject
} from "./chunk-7K4H5KUY.mjs";
import {
  RestApiService
} from "./chunk-D2QUIVVT.mjs";
import {
  API_ENDPOINTS,
  MethodTypes
} from "./chunk-XJ2RVBUZ.mjs";

// src/sdk/data/data.module.ts
var DataModule = class {
  constructor(apiKey = "") {
    this.apiKey$ = new ObjectSubject("");
    this.apiService = new RestApiService();
    this.switchCurrentApi(apiKey);
  }
  get currentApi() {
    return this.apiKey$.value;
  }
  switchCurrentApi(currentApi) {
    this.apiKey$.nextData(currentApi);
    return this.currentApi;
  }
  async getAccountBalances(account, chainId, tokens, provider) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        chainId,
        provider,
        tokens: tokens.length ? tokens : []
      };
      const balances = await this.apiService.makeRequest(API_ENDPOINTS.GET_ACCOUNT_BALANCES, MethodTypes.GET, queryParams);
      return balances;
    } catch (error) {
      throw new Error(error.message || "Failed to get account balances");
    }
  }
  async getTransaction(hash, chainId) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        hash,
        chainId
      };
      const response = await this.apiService.makeRequest(API_ENDPOINTS.GET_TRANSACTION, MethodTypes.GET, queryParams);
      return response.transaction;
    } catch (error) {
      throw new Error(error.message || "Failed to get transaction");
    }
  }
  async getTransactions(account, chainId, page, limit) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        chainId,
        page,
        limit
      };
      const response = await this.apiService.makeRequest(API_ENDPOINTS.GET_TRANSACTIONS, MethodTypes.GET, queryParams);
      return response;
    } catch (error) {
      throw new Error(error.message || "Failed to get transactions");
    }
  }
  async getNftList(account, chainId) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        chainId
      };
      const nfts = await this.apiService.makeRequest(API_ENDPOINTS.GET_ACCOUNT_NFTS, MethodTypes.GET, queryParams);
      return nfts;
    } catch (error) {
      throw new Error(error.message || "Failed to get nft list");
    }
  }
  async getAdvanceRoutesLiFi(fromTokenAddress, toTokenAddress, fromChainId, toChainId, fromAmount, toAddress, allowSwitchChain, fromAddress, showZeroUsd) {
    const account = fromAddress;
    let data = null;
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        fromTokenAddress,
        toTokenAddress,
        fromChainId,
        toChainId,
        fromAmount: fromAmount.toString(),
        toAddress,
        allowSwitchChain,
        fromAddress,
        showZeroUsd
      };
      const response = await this.apiService.makeRequest(API_ENDPOINTS.GET_ADVANCE_ROUTES_LIFI, MethodTypes.GET, queryParams);
      data = JSON.parse(response.data);
      return data;
    } catch (error) {
      throw new Error(error.message || "Failed to advance routes from LiFi");
    }
  }
  async getStepTransaction(selectedRoute, account) {
    try {
      const route = JSON.stringify(selectedRoute);
      const queryParams = {
        "api-key": this.currentApi
      };
      const body = {
        route,
        account
      };
      const response = await this.apiService.makeRequest(API_ENDPOINTS.GET_STEP_TRANSACTIONS, MethodTypes.POST, queryParams, body);
      return {
        items: response.transactions
      };
    } catch (error) {
      throw new Error(error.message || "Failed to get step transaction from LIFI");
    }
  }
  async getExchangeSupportedAssets(page = null, limit = null, chainId, account) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        page: page || 1,
        limit: limit || 100,
        chainId
      };
      const assets = await this.apiService.makeRequest(API_ENDPOINTS.GET_EXCHANGE_SUPPORTED_ASSETS, MethodTypes.GET, queryParams);
      return assets;
    } catch (error) {
      throw new Error(error.message || "Failed to get exchange supported assets");
    }
  }
  async getExchangeOffers(fromTokenAddress, toTokenAddress, fromAmount, fromChainId, fromAddress, toAddress, showZeroUsd) {
    const account = fromAddress;
    try {
      const queryParams = {
        "api-key": this.currentApi,
        account,
        fromTokenAddress,
        toTokenAddress,
        fromAmount: fromAmount.toString(),
        chainId: fromChainId,
        fromAddress,
        toAddress,
        showZeroUsd
      };
      const result = await this.apiService.makeRequest(API_ENDPOINTS.GET_EXCHANGE_OFFERS, MethodTypes.GET, queryParams);
      return result ? result.items : null;
    } catch (error) {
      throw new Error(error.message || "Failed to get exchange offers");
    }
  }
  async getTokenLists(chainId) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        chainId
      };
      const result = await this.apiService.makeRequest(API_ENDPOINTS.GET_TOKEN_LISTS, MethodTypes.GET, queryParams);
      return result ? result.items : [];
    } catch (error) {
      throw new Error(error.message || "Failed to get token lists");
    }
  }
  async getTokenListTokens(chainId, name = null) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        chainId,
        name
      };
      const result = await this.apiService.makeRequest(API_ENDPOINTS.GET_TOKEN_LIST_TOKENS, MethodTypes.GET, queryParams);
      return result ? result.tokens : [];
    } catch (error) {
      throw new Error(error.message || "Failed to get token list tokens");
    }
  }
  async fetchExchangeRates(tokens, chainId) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        chainId,
        tokens
      };
      const result = await this.apiService.makeRequest(API_ENDPOINTS.EXCHANGE_RATES, MethodTypes.GET, queryParams);
      return result ? result.exchangeRates : null;
    } catch (error) {
      throw new Error(error.message || "Failed to fetch exchange rates");
    }
  }
  async getSupportedAssets(chainId, provider) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        chainId
      };
      let apiUrl;
      switch (provider) {
        case "Connext" /* Connext */:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_SUPPORTED_ASSETS;
          break;
        default:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_SUPPORTED_ASSETS;
          break;
      }
      const result = await this.apiService.makeRequest(apiUrl, MethodTypes.GET, queryParams);
      return result ? result.tokens : [];
    } catch (error) {
      throw new Error(error.message || "Failed to get supported assets");
    }
  }
  async getQuotes(fromAddress, toAddress, fromChainId, toChainId, fromToken, fromAmount, slippage, provider) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        fromAddress,
        toAddress,
        fromChainId,
        toChainId,
        fromToken,
        fromAmount: fromAmount.toString(),
        slippage
      };
      let apiUrl;
      switch (provider) {
        case "Connext" /* Connext */:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_QUOTE_TRANSACTIONS;
          break;
        default:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_QUOTE_TRANSACTIONS;
          break;
      }
      const result = await this.apiService.makeRequest(apiUrl, MethodTypes.GET, queryParams);
      return result ? result : null;
    } catch (error) {
      throw new Error(error.message || "Failed to get quotes transactions");
    }
  }
  async getTransactionStatus(fromChainId, toChainId, transactionHash, provider) {
    try {
      const queryParams = {
        "api-key": this.currentApi,
        fromChainId,
        toChainId,
        transactionHash
      };
      let apiUrl;
      switch (provider) {
        case "Connext" /* Connext */:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_TRANSACTION_STATUS;
          break;
        default:
          apiUrl = API_ENDPOINTS.GET_CONNEXT_TRANSACTION_STATUS;
          break;
      }
      const result = await this.apiService.makeRequest(apiUrl, MethodTypes.GET, queryParams);
      return result ? result : null;
    } catch (error) {
      throw new Error(error.message || "Failed to get transaction status");
    }
  }
};

export {
  DataModule
};
//# sourceMappingURL=chunk-QCLH3UIP.mjs.map