package listing

import "testing"

func TestFilterAdminListingsByAssetLevels(t *testing.T) {
	items := []ListingDTO{
		{
			ID: 1,
			AssetSummary: map[string]any{
				"season_insurance": "3*3",
				"stamina_level":    "7级",
				"load_level":       "7级",
			},
		},
		{
			ID: 2,
			AssetSummary: map[string]any{
				"season_insurance": "2*3",
				"stamina_level":    "7级",
				"load_level":       "6级",
			},
		},
	}

	filtered := filterAdminListings(items, AdminListQuery{
		Insurance: []string{"3*3"},
		Stamina:   []string{"7级"},
		Load:      []string{"7级"},
	})

	if len(filtered) != 1 || filtered[0].ID != 1 {
		t.Fatalf("expected only listing 1 in 9/7/7 asset filter, got %#v", filtered)
	}
}

func TestFilterAdminListingsBySkinGroupAndName(t *testing.T) {
	items := []ListingDTO{
		{
			ID: 1,
			AssetSummary: map[string]any{
				"skin_groups": map[string]any{
					"operatorRed": []any{"凌霄成卫"},
					"weapon":      []any{"K416命运"},
				},
			},
		},
		{
			ID: 2,
			AssetSummary: map[string]any{
				"skin_groups": map[string]any{
					"operatorGold": []any{"露娜-金牌射手"},
				},
			},
		},
	}

	filtered := filterAdminListings(items, AdminListQuery{
		SkinGroup: []string{"operatorRed"},
		SkinName:  []string{"凌霄成卫"},
	})

	if len(filtered) != 1 || filtered[0].ID != 1 {
		t.Fatalf("expected only listing 1 by red skin name, got %#v", filtered)
	}
}

func TestFilterAdminListingsBySkinGroupOnly(t *testing.T) {
	items := []ListingDTO{
		{
			ID: 1,
			AssetSummary: map[string]any{
				"skin_groups": map[string]any{
					"operatorRed": []any{"凌霄成卫"},
				},
			},
		},
		{
			ID: 2,
			AssetSummary: map[string]any{
				"skin_groups": map[string]any{
					"operatorGold": []any{"露娜-金牌射手"},
				},
			},
		},
	}

	filtered := filterAdminListings(items, AdminListQuery{
		SkinGroup: []string{"operatorGold"},
	})

	if len(filtered) != 1 || filtered[0].ID != 2 {
		t.Fatalf("expected only listing 2 by gold skin group, got %#v", filtered)
	}
}
