package member

import (
	"testing"
)

func TestGetCodeNameByCode(t *testing.T) {
	tests := []struct {
		code     GenerateCodeType
		expected string
		ok       bool
	}{
		{GenerateCodeTypeEmail, "email", true},
		{GenerateCodeTypePhone, "phone", true},
		{GenerateCodeTypeForgetPassword, "forget_email", true},
		{GenerateCodeTypeNone, "", false},   // 無效代碼
		{GenerateCodeType(999), "", false},  // 無效代碼
		{GenerateCodeType(-999), "", false}, // 無效代碼
	}

	for _, tt := range tests {
		t.Run(tt.expected, func(t *testing.T) {
			result, ok := GetCodeNameByCode(tt.code)
			if result != tt.expected || ok != tt.ok {
				t.Errorf("GetCodeNameByCode(%v) = (%v, %v), want (%v, %v)",
					tt.code, result, ok, tt.expected, tt.ok)
			}
		})
	}
}

func TestGetGetCodeNameByCode(t *testing.T) {
	tests := []struct {
		name     string
		expected GenerateCodeType
	}{
		{"email", GenerateCodeTypeEmail},
		{"phone", GenerateCodeTypePhone},
		{"forget_email", GenerateCodeTypeForgetPassword},
		{"unknown", GenerateCodeTypeNone}, // 無效名稱
		{"", GenerateCodeTypeNone},        // 空名稱
		{"123", GenerateCodeTypeNone},     // 無效名稱
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := GetGetCodeNameByCode(tt.name)
			if result != tt.expected {
				t.Errorf("GetGetCodeNameByCode(%v) = %v, want %v",
					tt.name, result, tt.expected)
			}
		})
	}
}
