package user

import "testing"

func TestValidDisplayUserIDAllowsFiveDigitSeedAccounts(t *testing.T) {
	t.Parallel()

	valid := []string{"10001", "99999", "123456", "12345678901"}
	for _, value := range valid {
		if !ValidDisplayUserID(value) {
			t.Fatalf("display_user_id %s should be valid", value)
		}
	}

	invalid := []string{"", "09999", "9999", "123456789012", "12a45"}
	for _, value := range invalid {
		if ValidDisplayUserID(value) {
			t.Fatalf("display_user_id %s should be invalid", value)
		}
	}
}

func TestValidResolvableDisplayUserIDAllowsDefaultAndPrettyIDs(t *testing.T) {
	t.Parallel()

	valid := []string{"10001", "123456", "1111cc1111", "VIP2026", "ملك123", "Cafe\u0301123", "𝕸⃝é中⚡️™"}
	for _, value := range valid {
		if !ValidResolvableDisplayUserID(value) {
			t.Fatalf("resolvable display_user_id %q should be valid", value)
		}
	}

	invalid := []string{"", "   ", " VIP", "VIP ", "\nVIP", "VIP\x00"}
	for _, value := range invalid {
		if ValidResolvableDisplayUserID(value) {
			t.Fatalf("resolvable display_user_id %q should be invalid", value)
		}
	}
}

func TestValidAdminPrettyDisplayUserID(t *testing.T) {
	t.Parallel()

	// Unicode 字体可能含数学字母、组合标记、符号及 emoji；后台靓号必须完整保留这些展示字符。
	valid := []string{"VIP2026", "ملك123", "Cafe\u0301123", "𝕸⃝é中⚡️™", "VIP-2026", "VIP 2026", "VIP😀", "VIP!"}
	for _, value := range valid {
		if !ValidAdminPrettyDisplayUserID(value) {
			t.Fatalf("admin pretty display_user_id %q should be valid", value)
		}
	}

	invalid := []string{"", "   ", " VIP", "VIP ", "\nVIP", "VIP\x00"}
	for _, value := range invalid {
		if ValidAdminPrettyDisplayUserID(value) {
			t.Fatalf("admin pretty display_user_id %q should be invalid", value)
		}
	}
}

func TestValidPrettyDisplayIDRuleType(t *testing.T) {
	t.Parallel()

	valid := []string{
		PrettyDisplayIDRuleAABBCC,
		PrettyDisplayIDRuleAAAA,
		PrettyDisplayIDRuleABAB,
		PrettyDisplayIDRuleABCDEF,
		PrettyDisplayIDRuleFEDCBA,
		PrettyDisplayIDRuleDateYYYYMMDD,
		PrettyDisplayIDRuleLove,
		PrettyDisplayIDRuleCustomValues,
		PrettyDisplayIDRuleCustomPattern,
	}
	for _, ruleType := range valid {
		if !ValidPrettyDisplayIDRuleType(ruleType) {
			t.Fatalf("rule_type %s should be valid", ruleType)
		}
	}

	for _, ruleType := range []string{"", "random", "aabbccddxx"} {
		if ValidPrettyDisplayIDRuleType(ruleType) {
			t.Fatalf("rule_type %s should be invalid", ruleType)
		}
	}
}
