package okx

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/thrasher-corp/gocryptotrader/exchanges/request"
)

func TestRateLimit_LimitStatic(t *testing.T) {
	t.Parallel()
	testTable := map[string]request.EndpointLimit{
		"placeOrder":                                     placeOrderEPL,
		"placeMultipleOrders":                            placeMultipleOrdersEPL,
		"cancelOrder":                                    cancelOrderEPL,
		"cancelMultipleOrders":                           cancelMultipleOrdersEPL,
		"amendOrder":                                     amendOrderEPL,
		"amendMultipleOrders":                            amendMultipleOrdersEPL,
		"closePosition":                                  closePositionEPL,
		"getOrderDet":                                    getOrderDetEPL,
		"getOrderList":                                   getOrderListEPL,
		"getOrderHistory7Days":                           getOrderHistory7DaysEPL,
		"getOrderHistory3Months":                         getOrderHistory3MonthsEPL,
		"getTransactionDetail3Days":                      getTransactionDetail3DaysEPL,
		"getTransactionDetail3Months":                    getTransactionDetail3MonthsEPL,
		"setTransactionDetail2YearInterval":              setTransactionDetail2YearIntervalEPL,
		"getTransactionDetailLast2Years":                 getTransactionDetailLast2YearsEPL,
		"cancelAllAfterCountdown":                        cancelAllAfterCountdownEPL,
		"placeAlgoOrder":                                 placeAlgoOrderEPL,
		"cancelAlgoOrder":                                cancelAlgoOrderEPL,
		"amendAlgoOrder":                                 amendAlgoOrderEPL,
		"cancelAdvanceAlgoOrder":                         cancelAdvanceAlgoOrderEPL,
		"getAlgoOrderDetail":                             getAlgoOrderDetailEPL,
		"getAlgoOrderList":                               getAlgoOrderListEPL,
		"getAlgoOrderHistory":                            getAlgoOrderHistoryEPL,
		"getEasyConvertCurrencyList":                     getEasyConvertCurrencyListEPL,
		"placeEasyConvert":                               placeEasyConvertEPL,
		"getEasyConvertHistory":                          getEasyConvertHistoryEPL,
		"getOneClickRepayHistory":                        getOneClickRepayHistoryEPL,
		"oneClickRepayCurrencyList":                      oneClickRepayCurrencyListEPL,
		"tradeOneClickRepay":                             tradeOneClickRepayEPL,
		"massCancelMMPOrder":                             massCancelMMPOrderEPL,
		"getCounterparties":                              getCounterpartiesEPL,
		"createRFQ":                                      createRFQEPL,
		"cancelRFQ":                                      cancelRFQEPL,
		"cancelMultipleRFQ":                              cancelMultipleRFQEPL,
		"cancelAllRFQs":                                  cancelAllRFQsEPL,
		"executeQuote":                                   executeQuoteEPL,
		"getQuoteProducts":                               getQuoteProductsEPL,
		"setQuoteProducts":                               setQuoteProductsEPL,
		"resetRFQMMP":                                    resetRFQMMPEPL,
		"setMMP":                                         setMMPEPL,
		"getMMPConfig":                                   getMMPConfigEPL,
		"createQuote":                                    createQuoteEPL,
		"cancelQuote":                                    cancelQuoteEPL,
		"cancelMultipleQuotes":                           cancelMultipleQuotesEPL,
		"cancelAllQuotes":                                cancelAllQuotesEPL,
		"getRFQs":                                        getRFQsEPL,
		"getQuotes":                                      getQuotesEPL,
		"getTrades":                                      getTradesEPL,
		"getTradesHistory":                               getTradesHistoryEPL,
		"optionInstrumentTradeFamily":                    optionInstrumentTradeFamilyEPL,
		"optionTrades":                                   optionTradesEPL,
		"getPublicTrades":                                getPublicTradesEPL,
		"getCurrencies":                                  getCurrenciesEPL,
		"getBalance":                                     getBalanceEPL,
		"getNonTradableAssets":                           getNonTradableAssetsEPL,
		"getAccountAssetValuation":                       getAccountAssetValuationEPL,
		"fundsTransfer":                                  fundsTransferEPL,
		"getFundsTransferState":                          getFundsTransferStateEPL,
		"assetBillsDetails":                              assetBillsDetailsEPL,
		"lightningDeposits":                              lightningDepositsEPL,
		"getDepositAddress":                              getDepositAddressEPL,
		"getDepositHistory":                              getDepositHistoryEPL,
		"withdrawal":                                     withdrawalEPL,
		"lightningWithdrawals":                           lightningWithdrawalsEPL,
		"cancelWithdrawal":                               cancelWithdrawalEPL,
		"getWithdrawalHistory":                           getWithdrawalHistoryEPL,
		"getDepositWithdrawalStatus":                     getDepositWithdrawalStatusEPL,
		"smallAssetsConvert":                             smallAssetsConvertEPL,
		"getPublicExchangeList":                          getPublicExchangeListEPL,
		"getSavingBalance":                               getSavingBalanceEPL,
		"savingsPurchaseRedemption":                      savingsPurchaseRedemptionEPL,
		"setLendingRate":                                 setLendingRateEPL,
		"getLendingHistory":                              getLendingHistoryEPL,
		"getPublicBorrowInfo":                            getPublicBorrowInfoEPL,
		"getPublicBorrowHistory":                         getPublicBorrowHistoryEPL,
		"getConvertCurrencies":                           getConvertCurrenciesEPL,
		"getConvertCurrencyPair":                         getConvertCurrencyPairEPL,
		"estimateQuote":                                  estimateQuoteEPL,
		"convertTrade":                                   convertTradeEPL,
		"getConvertHistory":                              getConvertHistoryEPL,
		"getAccountBalance":                              getAccountBalanceEPL,
		"getPositions":                                   getPositionsEPL,
		"getPositionsHistory":                            getPositionsHistoryEPL,
		"getAccountAndPositionRisk":                      getAccountAndPositionRiskEPL,
		"getBillsDetails":                                getBillsDetailsEPL,
		"getBillsDetailArchive":                          getBillsDetailArchiveEPL,
		"getAccountConfiguration":                        getAccountConfigurationEPL,
		"setPositionMode":                                setPositionModeEPL,
		"setLeverage":                                    setLeverageEPL,
		"getMaximumBuyOrSellAmount":                      getMaximumBuyOrSellAmountEPL,
		"getMaximumAvailableTradableAmount":              getMaximumAvailableTradableAmountEPL,
		"increaseOrDecreaseMargin":                       increaseOrDecreaseMarginEPL,
		"getLeverage":                                    getLeverageEPL,
		"getLeverateEstimatedInfo":                       getLeverateEstimatedInfoEPL,
		"getTheMaximumLoanOfInstrument":                  getTheMaximumLoanOfInstrumentEPL,
		"getFeeRates":                                    getFeeRatesEPL,
		"getInterestAccruedData":                         getInterestAccruedDataEPL,
		"getInterestRate":                                getInterestRateEPL,
		"setGreeks":                                      setGreeksEPL,
		"isolatedMarginTradingSettings":                  isolatedMarginTradingSettingsEPL,
		"getMaximumWithdrawals":                          getMaximumWithdrawalsEPL,
		"getAccountRiskState":                            getAccountRiskStateEPL,
		"manualBorrowAndRepay":                           manualBorrowAndRepayEPL,
		"getBorrowAndRepayHistory":                       getBorrowAndRepayHistoryEPL,
		"vipLoansBorrowAnsRepay":                         vipLoansBorrowAnsRepayEPL,
		"getBorrowAnsRepayHistoryHistory":                getBorrowAnsRepayHistoryHistoryEPL,
		"getVIPInterestAccruedData":                      getVIPInterestAccruedDataEPL,
		"getVIPInterestDeductedData":                     getVIPInterestDeductedDataEPL,
		"getVIPLoanOrderList":                            getVIPLoanOrderListEPL,
		"getVIPLoanOrderDetail":                          getVIPLoanOrderDetailEPL,
		"getBorrowInterestAndLimit":                      getBorrowInterestAndLimitEPL,
		"positionBuilder":                                positionBuilderEPL,
		"getGreeks":                                      getGreeksEPL,
		"getPMLimitation":                                getPMLimitationEPL,
		"setRiskOffsetLimiter":                           setRiskOffsetLimiterEPL,
		"activateOption":                                 activateOptionEPL,
		"setAutoLoan":                                    setAutoLoanEPL,
		"setAccountLevel":                                setAccountLevelEPL,
		"resetMMPStatus":                                 resetMMPStatusEPL,
		"viewSubaccountList":                             viewSubaccountListEPL,
		"resetSubAccountAPIKey":                          resetSubAccountAPIKeyEPL,
		"getSubaccountTradingBalance":                    getSubaccountTradingBalanceEPL,
		"getSubaccountFundingBalance":                    getSubaccountFundingBalanceEPL,
		"getSubAccountMaxWithdrawal":                     getSubAccountMaxWithdrawalEPL,
		"historyOfSubaccountTransfer":                    historyOfSubaccountTransferEPL,
		"managedSubAccountTransfer":                      managedSubAccountTransferEPL,
		"masterAccountsManageTransfersBetweenSubaccount": masterAccountsManageTransfersBetweenSubaccountEPL,
		"setPermissionOfTransferOut":                     setPermissionOfTransferOutEPL,
		"getCustodyTradingSubaccountList":                getCustodyTradingSubaccountListEPL,
		"setSubAccountVIPLoanAllocation":                 setSubAccountVIPLoanAllocationEPL,
		"getSubAccountBorrowInterestAndLimit":            getSubAccountBorrowInterestAndLimitEPL,
		"gridTrading":                                    gridTradingEPL,
		"amendGridAlgoOrder":                             amendGridAlgoOrderEPL,
		"stopGridAlgoOrder":                              stopGridAlgoOrderEPL,
		"closePositionForForContractGrid":                closePositionForForContractGridEPL,
		"cancelClosePositionOrderForContractGrid":        cancelClosePositionOrderForContractGridEPL,
		"instantTriggerGridAlgoOrder":                    instantTriggerGridAlgoOrderEPL,
		"getGridAlgoOrderList":                           getGridAlgoOrderListEPL,
		"getGridAlgoOrderHistory":                        getGridAlgoOrderHistoryEPL,
		"getGridAlgoOrderDetails":                        getGridAlgoOrderDetailsEPL,
		"getGridAlgoSubOrders":                           getGridAlgoSubOrdersEPL,
		"getGridAlgoOrderPositions":                      getGridAlgoOrderPositionsEPL,
		"spotGridWithdrawIncome":                         spotGridWithdrawIncomeEPL,
		"computeMarginBalance":                           computeMarginBalanceEPL,
		"adjustMarginBalance":                            adjustMarginBalanceEPL,
		"getGridAIParameter":                             getGridAIParameterEPL,
		"computeMinInvestment":                           computeMinInvestmentEPL,
		"rsiBackTesting":                                 rsiBackTestingEPL,
		"signalBotOrderDetails":                          signalBotOrderDetailsEPL,
		"signalBotOrderPositions":                        signalBotOrderPositionsEPL,
		"signalBotSubOrders":                             signalBotSubOrdersEPL,
		"signalBotEventHistory":                          signalBotEventHistoryEPL,
		"placeRecurringBuyOrder":                         placeRecurringBuyOrderEPL,
		"amendRecurringBuyOrder":                         amendRecurringBuyOrderEPL,
		"stopRecurringBuyOrder":                          stopRecurringBuyOrderEPL,
		"getRecurringBuyOrderList":                       getRecurringBuyOrderListEPL,
		"getRecurringBuyOrderHistory":                    getRecurringBuyOrderHistoryEPL,
		"getRecurringBuyOrderDetail":                     getRecurringBuyOrderDetailEPL,
		"getRecurringBuySubOrders":                       getRecurringBuySubOrdersEPL,
		"getExistingLeadingPositions":                    getExistingLeadingPositionsEPL,
		"getLeadingPositionHistory":                      getLeadingPositionHistoryEPL,
		"placeLeadingStopOrder":                          placeLeadingStopOrderEPL,
		"closeLeadingPosition":                           closeLeadingPositionEPL,
		"getLeadingInstruments":                          getLeadingInstrumentsEPL,
		"getProfitSharingLimit":                          getProfitSharingLimitEPL,
		"getTotalProfitSharing":                          getTotalProfitSharingEPL,
		"setFirstCopySettings":                           setFirstCopySettingsEPL,
		"amendFirstCopySettings":                         amendFirstCopySettingsEPL,
		"stopCopying":                                    stopCopyingEPL,
		"getCopySettings":                                getCopySettingsEPL,
		"getMultipleLeverages":                           getMultipleLeveragesEPL,
		"setBatchLeverage":                               setBatchLeverageEPL,
		"getMyLeadTraders":                               getMyLeadTradersEPL,
		"getLeadTraderRanks":                             getLeadTraderRanksEPL,
		"getLeadTraderWeeklyPNL":                         getLeadTraderWeeklyPNLEPL,
		"getLeadTraderDailyPNL":                          getLeadTraderDailyPNLEPL,
		"getLeadTraderStats":                             getLeadTraderStatsEPL,
		"getLeadTraderCurrencyPreferences":               getLeadTraderCurrencyPreferencesEPL,
		"getTraderCurrentLeadPositions":                  getTraderCurrentLeadPositionsEPL,
		"getLeadTraderLeadPositionHistory":               getLeadTraderLeadPositionHistoryEPL,
		"getOffer":                                       getOfferEPL,
		"purchase":                                       purchaseEPL,
		"redeem":                                         redeemEPL,
		"cancelPurchaseOrRedemption":                     cancelPurchaseOrRedemptionEPL,
		"getEarnActiveOrders":                            getEarnActiveOrdersEPL,
		"getFundingOrderHistory":                         getFundingOrderHistoryEPL,
		"purchaseETHStaking":                             purchaseETHStakingEPL,
		"redeemETHStaking":                               redeemETHStakingEPL,
		"getBETHBalance":                                 getBETHBalanceEPL,
		"getPurchaseRedeemHistory":                       getPurchaseRedeemHistoryEPL,
		"getAPYHistory":                                  getAPYHistoryEPL,
		"getTickers":                                     getTickersEPL,
		"getTicker":                                      getTickerEPL,
		"getIndexTickers":                                getIndexTickersEPL,
		"getOrderBook":                                   getOrderBookEPL,
		"getOrderBookLite":                               getOrderBookLiteEPL,
		"getCandlesticks":                                getCandlesticksEPL,
		"getTradesRequest":                               getTradesRequestEPL,
		"get24HTotalVolume":                              get24HTotalVolumeEPL,
		"getOracle":                                      getOracleEPL,
		"getExchangeRateRequest":                         getExchangeRateRequestEPL,
		"getIndexComponents":                             getIndexComponentsEPL,
		"getBlockTickers":                                getBlockTickersEPL,
		"getBlockTrades":                                 getBlockTradesEPL,
		"placeSpreadOrder":                               placeSpreadOrderEPL,
		"cancelSpreadOrder":                              cancelSpreadOrderEPL,
		"cancelAllSpreadOrder":                           cancelAllSpreadOrderEPL,
		"amendSpreadOrder":                               amendSpreadOrderEPL,
		"getSpreadOrderDetails":                          getSpreadOrderDetailsEPL,
		"getSpreadOrderTrades":                           getSpreadOrderTradesEPL,
		"getSpreads":                                     getSpreadsEPL,
		"getSpreadOrderbook":                             getSpreadOrderbookEPL,
		"getSpreadTicker":                                getSpreadTickerEPL,
		"getSpreadPublicTrades":                          getSpreadPublicTradesEPL,
		"getActiveSpreadOrders":                          getActiveSpreadOrdersEPL,
		"getSpreadOrders7Days":                           getSpreadOrders7DaysEPL,
		"getInstruments":                                 getInstrumentsEPL,
		"getDeliveryExerciseHistory":                     getDeliveryExerciseHistoryEPL,
		"getOpenInterest":                                getOpenInterestEPL,
		"getFunding":                                     getFundingEPL,
		"getFundingRateHistory":                          getFundingRateHistoryEPL,
		"getLimitPrice":                                  getLimitPriceEPL,
		"getOptionMarketDate":                            getOptionMarketDateEPL,
		"getEstimatedDeliveryExercisePrice":              getEstimatedDeliveryExercisePriceEPL,
		"getDiscountRateAndInterestFreeQuota":            getDiscountRateAndInterestFreeQuotaEPL,
		"getSystemTime":                                  getSystemTimeEPL,
		"getLiquidationOrders":                           getLiquidationOrdersEPL,
		"getMarkPrice":                                   getMarkPriceEPL,
		"getPositionTiers":                               getPositionTiersEPL,
		"getInterestRateAndLoanQuota":                    getInterestRateAndLoanQuotaEPL,
		"getInterestRateAndLoanQuoteForVIPLoans":         getInterestRateAndLoanQuoteForVIPLoansEPL,
		"getUnderlying":                                  getUnderlyingEPL,
		"getInsuranceFund":                               getInsuranceFundEPL,
		"unitConvert":                                    unitConvertEPL,
		"optionTickBands":                                optionTickBandsEPL,
		"getIndexTicker":                                 getIndexTickerEPL,
		"getSupportCoin":                                 getSupportCoinEPL,
		"getTakerVolume":                                 getTakerVolumeEPL,
		"getMarginLendingRatio":                          getMarginLendingRatioEPL,
		"getLongShortRatio":                              getLongShortRatioEPL,
		"getContractsOpenInterestAndVolume":              getContractsOpenInterestAndVolumeEPL,
		"getOptionsOpenInterestAndVolume":                getOptionsOpenInterestAndVolumeEPL,
		"getPutCallRatio":                                getPutCallRatioEPL,
		"getOpenInterestAndVolume":                       getOpenInterestAndVolumeEPL,
		"getTakerFlow":                                   getTakerFlowEPL,
		"getEventStatus":                                 getEventStatusEPL,
		"getCandlestickHistory":                          getCandlestickHistoryEPL,
		"getIndexCandlesticks":                           getIndexCandlesticksEPL,
		"getIndexCandlesticksHistory":                    getIndexCandlesticksHistoryEPL,
		"getMarkPriceCandlesticksHistory":                getMarkPriceCandlesticksHistoryEPL,
		"getEconomicCalendar":                            getEconomicCalendarEPL,
		"getEstimatedDeliveryPrice":                      getEstimatedDeliveryPriceEPL,
		"getAffilateInviteesDetail":                      getAffilateInviteesDetailEPL,
		"getUserAffilateRebateInformation":               getUserAffiliateRebateInformationEPL,
	}

	rl, err := request.New("RateLimit_Static", http.DefaultClient, request.WithLimiter(rateLimits))
	require.NoError(t, err)

	for name, tt := range testTable {
		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if err := rl.InitiateRateLimit(t.Context(), tt); err != nil {
				t.Fatalf("error applying rate limit: %v", err)
			}
		})
	}
}
