package appconfig

import "testing"

func TestNormalizeBannerDisplayScopeAcceptsChineseLabels(t *testing.T) {
	cases := map[string]string{
		"":     "home",
		"首页":   "home",
		"房间内":  "room",
		"充值页":  "recharge",
		"我的页":  "me",
		"ME":   "me",
		"ROOM": "room",
		"bad":  "",
	}
	for input, want := range cases {
		if got := NormalizeBannerDisplayScope(input); got != want {
			t.Fatalf("scope %q mismatch: got %q want %q", input, got, want)
		}
	}
}

func TestBannerDisplayScopeListParsesMultiScopeValue(t *testing.T) {
	got := bannerDisplayScopeList("room,home,recharge,me")
	want := []string{"home", "room", "recharge", "me"}
	if len(got) != len(want) {
		t.Fatalf("scope count mismatch: got %+v want %+v", got, want)
	}
	for index := range want {
		if got[index] != want[index] {
			t.Fatalf("scope %d mismatch: got %+v want %+v", index, got, want)
		}
	}
}

func TestParseRoomRegionWhitelistSupportsObjectAndArrayPayloads(t *testing.T) {
	cases := []string{
		`{"user_ids":["325379237278126080","1001","1001","0","bad"]}`,
		`["325379237278126080","1001","1001","0","bad"]`,
	}
	for _, input := range cases {
		got, err := parseRoomRegionWhitelist(input)
		if err != nil {
			t.Fatalf("parse whitelist %s failed: %v", input, err)
		}
		if _, ok := got[325379237278126080]; !ok {
			t.Fatalf("long user id missing: %+v", got)
		}
		if _, ok := got[1001]; !ok {
			t.Fatalf("small user id missing: %+v", got)
		}
		if _, ok := got[0]; ok {
			t.Fatalf("zero user id must be ignored: %+v", got)
		}
	}
}
