package hostorg

import "testing"

// TestNormalizeListQueryAllowsCoinSellerComputedSorts 锁定币商余额和累充 USDT 排序字段会被后台列表查询接受。
func TestNormalizeListQueryAllowsCoinSellerComputedSorts(t *testing.T) {
	for _, sortBy := range []string{sortByMerchantBalance, sortByTotalRechargeUSDT} {
		query := normalizeListQuery(listQuery{Page: 1, PageSize: 50, SortBy: sortBy, SortDirection: "asc"})
		if query.SortBy != sortBy || query.SortDirection != "asc" {
			t.Fatalf("expected sort %s asc to be kept, got sort_by=%q direction=%q", sortBy, query.SortBy, query.SortDirection)
		}
	}
}

// TestSortCoinSellerListItemsComputedFields 验证 wallet 聚合字段排序只改变展示顺序，不改动币商身份数据。
func TestSortCoinSellerListItemsComputedFields(t *testing.T) {
	items := []*CoinSellerListItem{
		{UserID: 1, MerchantBalance: 100, TotalRechargeUSDTMicro: 30_000_000},
		{UserID: 2, MerchantBalance: 300, TotalRechargeUSDTMicro: 10_000_000},
		{UserID: 3, MerchantBalance: 200, TotalRechargeUSDTMicro: 20_000_000},
	}

	sortCoinSellerListItems(items, sortByMerchantBalance, "desc")
	if got := []int64{items[0].UserID, items[1].UserID, items[2].UserID}; got[0] != 2 || got[1] != 3 || got[2] != 1 {
		t.Fatalf("merchant balance desc order mismatch: %v", got)
	}

	sortCoinSellerListItems(items, sortByTotalRechargeUSDT, "asc")
	if got := []int64{items[0].UserID, items[1].UserID, items[2].UserID}; got[0] != 2 || got[1] != 3 || got[2] != 1 {
		t.Fatalf("total recharge usdt asc order mismatch: %v", got)
	}
}
