package kucoin

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{
		"all Account":                                      allAccountEPL,
		"account Detail":                                   accountDetailEPL,
		"account Ledgers":                                  accountLedgersEPL,
		"hf Account Ledgers":                               hfAccountLedgersEPL,
		"hf Account Ledgers Margin":                        hfAccountLedgersMarginEPL,
		"futures Account Ledgers":                          futuresAccountLedgersEPL,
		"sub Account Info V1":                              subAccountInfoV1EPL,
		"all Sub Accounts Info V2":                         allSubAccountsInfoV2EPL,
		"create SubUser":                                   createSubUserEPL,
		"sub Accounts":                                     subAccountsEPL,
		"sub Account Balances":                             subAccountBalancesEPL,
		"all SubAccount Balances V2":                       allSubAccountBalancesV2EPL,
		"sub Account Spot API List":                        subAccountSpotAPIListEPL,
		"create Spot API For Sub Account":                  createSpotAPIForSubAccountEPL,
		"modify Sub Account Spot API":                      modifySubAccountSpotAPIEPL,
		"delete Sub Account Spot API":                      deleteSubAccountSpotAPIEPL,
		"margin Account Detail":                            marginAccountDetailEPL,
		"cross Margin Accounts Detail":                     crossMarginAccountsDetailEPL,
		"isolated Margin Account Detail":                   isolatedMarginAccountDetailEPL,
		"futures Accounts Detail":                          futuresAccountsDetailEPL,
		"all Futures Sub Account Balances":                 allFuturesSubAccountBalancesEPL,
		"create Deposit Address":                           createDepositAddressEPL,
		"deposit Addresses V2":                             depositAddressesV2EPL,
		"deposit Addresses V1":                             depositAddressesV1EPL,
		"deposit List":                                     depositListEPL,
		"historic Deposit List":                            historicDepositListEPL,
		"withdrawal List":                                  withdrawalListEPL,
		"retrieve V1 Historical Withdrawal List":           retrieveV1HistoricalWithdrawalListEPL,
		"withdrawal Quota":                                 withdrawalQuotaEPL,
		"apply Withdrawal":                                 applyWithdrawalEPL,
		"cancel Withdrawals":                               cancelWithdrawalsEPL,
		"get Transferables":                                getTransferablesEPL,
		"flexi Transfer":                                   flexiTransferEPL,
		"master Sub User Transfer":                         masterSubUserTransferEPL,
		"inner Transfer":                                   innerTransferEPL,
		"to Main Or TradeAccount":                          toMainOrTradeAccountEPL,
		"to Futures Account":                               toFuturesAccountEPL,
		"futures Transfer Out Request Records":             futuresTransferOutRequestRecordsEPL,
		"basic Fees":                                       basicFeesEPL,
		"trade Fees":                                       tradeFeesEPL,
		"spot Currencies V3":                               spotCurrenciesV3EPL,
		"spot Currency Detail":                             spotCurrencyDetailEPL,
		"symbols":                                          symbolsEPL,
		"tickers":                                          tickersEPL,
		"all Tickers":                                      allTickersEPL,
		"statistics 24Hr":                                  statistics24HrEPL,
		"market List":                                      marketListEPL,
		"part Orderbook 20":                                partOrderbook20EPL,
		"part Orderbook 100":                               partOrderbook100EPL,
		"full Orderbook":                                   fullOrderbookEPL,
		"trade History":                                    tradeHistoryEPL,
		"klines":                                           klinesEPL,
		"fiat Price":                                       fiatPriceEPL,
		"current Server Time":                              currentServerTimeEPL,
		"service Status":                                   serviceStatusEPL,
		"hf Place Order":                                   hfPlaceOrderEPL,
		"hf Sync Place Order":                              hfSyncPlaceOrderEPL,
		"hf Multiple Orders":                               hfMultipleOrdersEPL,
		"hf Sync Place Multiple HF Orders":                 hfSyncPlaceMultipleHFOrdersEPL,
		"hf Modify Order":                                  hfModifyOrderEPL,
		"cancel HF Order":                                  cancelHFOrderEPL,
		"hf Sync Cancel Order":                             hfSyncCancelOrderEPL,
		"hf Cancel Order By Client OrderID":                hfCancelOrderByClientOrderIDEPL,
		"cancel Specified Number HF Orders By OrderID":     cancelSpecifiedNumberHFOrdersByOrderIDEPL,
		"hf Cancel All Orders By Symbol":                   hfCancelAllOrdersBySymbolEPL,
		"hf Cancel All Orders":                             hfCancelAllOrdersEPL,
		"hf Get All Active Orders":                         hfGetAllActiveOrdersEPL,
		"hf Symbols With Active Orders":                    hfSymbolsWithActiveOrdersEPL,
		"hf Completed Order List":                          hfCompletedOrderListEPL,
		"hf Order Detail By OrderID":                       hfOrderDetailByOrderIDEPL,
		"auto Cancel HF Order Setting":                     autoCancelHFOrderSettingEPL,
		"auto Cancel HF Order Setting Query":               autoCancelHFOrderSettingQueryEPL,
		"hf Filled List":                                   hfFilledListEPL,
		"place Order":                                      placeOrderEPL,
		"place Bulk Orders":                                placeBulkOrdersEPL,
		"cancel Order":                                     cancelOrderEPL,
		"cancel Order By Client OrderID":                   cancelOrderByClientOrderIDEPL,
		"cancel All Orders":                                cancelAllOrdersEPL,
		"list Orders":                                      listOrdersEPL,
		"recent Orders":                                    recentOrdersEPL,
		"order Detail By ID":                               orderDetailByIDEPL,
		"get Order By Client Supplied OrderID":             getOrderByClientSuppliedOrderIDEPL,
		"list Fills":                                       listFillsEPL,
		"get Recent Fills":                                 getRecentFillsEPL,
		"place Stop Order":                                 placeStopOrderEPL,
		"cancel Stop Order":                                cancelStopOrderEPL,
		"cancel Stop Order By ClientID":                    cancelStopOrderByClientIDEPL,
		"cancel Stop Orders":                               cancelStopOrdersEPL,
		"list Stop Orders":                                 listStopOrdersEPL,
		"get Stop Order Detail":                            getStopOrderDetailEPL,
		"get Stop Order By ClientID":                       getStopOrderByClientIDEPL,
		"place OCO Order":                                  placeOCOOrderEPL,
		"cancel OCOOrder By ID":                            cancelOCOOrderByIDEPL,
		"cancel Multiple OCO Orders":                       cancelMultipleOCOOrdersEPL,
		"get OCO Order By ID":                              getOCOOrderByIDEPL,
		"get OCO Order Details By OrderID":                 getOCOOrderDetailsByOrderIDEPL,
		"get OCO Orders":                                   getOCOOrdersEPL,
		"place Margin Order":                               placeMarginOrderEPL,
		"cancel Margin HF Order By ID":                     cancelMarginHFOrderByIDEPL,
		"get Margin HF Order Detail By ID":                 getMarginHFOrderDetailByID,
		"cancel All Margin HF Orders By Symbol":            cancelAllMarginHFOrdersBySymbolEPL,
		"get Active Margin HF Orders":                      getActiveMarginHFOrdersEPL,
		"get Filled HF Margin Orders":                      getFilledHFMarginOrdersEPL,
		"get Margin HF Order Detail By Order ID":           getMarginHFOrderDetailByOrderIDEPL,
		"get Margin HF Trade Fills":                        getMarginHFTradeFillsEPL,
		"place Margin Orders":                              placeMarginOrdersEPL,
		"leveraged Token Info":                             leveragedTokenInfoEPL,
		"get Mark Price":                                   getMarkPriceEPL,
		"get Margin Configuration":                         getMarginConfigurationEPL,
		"cross Isolated Margin Risk Limit Currency Config": crossIsolatedMarginRiskLimitCurrencyConfigEPL,
		"isolated Margin Pair Config":                      isolatedMarginPairConfigEPL,
		"isolated Margin Account Info":                     isolatedMarginAccountInfoEPL,
		"single Isolated Margin Account Info":              singleIsolatedMarginAccountInfoEPL,
		"post Margin Borrow Order":                         postMarginBorrowOrderEPL,
		"post Margin Repayment":                            postMarginRepaymentEPL,
		"margin Borrowing History":                         marginBorrowingHistoryEPL,
		"margin Repayment History":                         marginRepaymentHistoryEPL,
		"lending Currency Info":                            lendingCurrencyInfoEPL,
		"interest Rate":                                    interestRateEPL,
		"margin Lending Subscription":                      marginLendingSubscriptionEPL,
		"redemption":                                       redemptionEPL,
		"modify Subscription":                              modifySubscriptionEPL,
		"get Redemption Orders":                            getRedemptionOrdersEPL,
		"get Subscription Orders":                          getSubscriptionOrdersEPL,
		"futures Open Contracts":                           futuresOpenContractsEPL,
		"futures Contract":                                 futuresContractEPL,
		"futures Ticker":                                   futuresTickerEPL,
		"futures Orderbook":                                futuresOrderbookEPL,
		"futures Part Orderbook Depth20":                   futuresPartOrderbookDepth20EPL,
		"futures Part Orderbook Depth100":                  futuresPartOrderbookDepth100EPL,
		"futures Transaction History":                      futuresTransactionHistoryEPL,
		"futures Kline":                                    futuresKlineEPL,
		"futures Interest Rate":                            futuresInterestRateEPL,
		"futures Index List":                               futuresIndexListEPL,
		"futures Current Mark Price":                       futuresCurrentMarkPriceEPL,
		"futures Premium Index":                            futuresPremiumIndexEPL,
		"futures Transaction Volume":                       futuresTransactionVolumeEPL,
		"futures Server Time":                              futuresServerTimeEPL,
		"futures Service Status":                           futuresServiceStatusEPL,
		"multiple Futures Orders":                          multipleFuturesOrdersEPL,
		"futures Cancel An Order":                          futuresCancelAnOrderEPL,
		"futures Place Order":                              futuresPlaceOrderEPL,
		"futures Limit Order Mass Cancellation":            futuresLimitOrderMassCancelationEPL,
		"cancel Untriggered Futures Stop Orders":           cancelUntriggeredFuturesStopOrdersEPL,
		"futures Cancel Multiple Limit Orders":             futuresCancelMultipleLimitOrdersEPL,
		"futures Retrieve Order List":                      futuresRetrieveOrderListEPL,
		"futures Recent Completed Orders":                  futuresRecentCompletedOrdersEPL,
		"futures Orders By ID":                             futuresOrdersByIDEPL,
		"futures Retrieve Fills":                           futuresRetrieveFillsEPL,
		"futures Recent Fills":                             futuresRecentFillsEPL,
		"futures Open Order Stats":                         futuresOpenOrderStatsEPL,
		"futures Position":                                 futuresPositionEPL,
		"futures Position List":                            futuresPositionListEPL,
		"set Auto Deposit Margin":                          setAutoDepositMarginEPL,
		"max Withdraw Margin":                              maxWithdrawMarginEPL,
		"remove Margin Manually":                           removeMarginManuallyEPL,
		"futures Add Margin Manually":                      futuresAddMarginManuallyEPL,
		"futures Risk Limit Level":                         futuresRiskLimitLevelEPL,
		"futures Update Risk Limit Level":                  futuresUpdateRiskLimitLevelEPL,
		"futures Current Funding Rate":                     futuresCurrentFundingRateEPL,
		"futures Public Funding Rate":                      futuresPublicFundingRateEPL,
		"futures Funding History":                          futuresFundingHistoryEPL,
		"spot Authentication":                              spotAuthenticationEPL,
		"futures Authentication":                           futuresAuthenticationEPL,
		"futures Order Details By Client Order ID":         futuresOrderDetailsByClientOrderIDEPL,
		"modify Sub Account API":                           modifySubAccountAPIEPL,
		"all Sub Accounts Balance":                         allSubAccountsBalanceEPL,
		"all User Sub Accounts V2":                         allUserSubAccountsV2EPL,
		"futures Retrieve Transaction History":             futuresRetrieveTransactionHistoryEPL,
		"futures Account Overview":                         futuresAccountOverviewEPL,
		"create Sub Account API Key":                       createSubAccountAPIKeyEPL,
		"transfer Out To Main":                             transferOutToMainEPL,
		"transfer Fund To Futures Account":                 transferFundToFuturesAccountEPL,
		"futures Transfer Out List":                        futuresTransferOutListEPL,
	}
	rl, err := request.New("rateLimitTest2", http.DefaultClient, request.WithLimiter(GetRateLimit()))
	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)
			}
		})
	}
}
