package utils

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestValidateLanguage(t *testing.T) {
	tests := []struct {
		name      string
		language  string
		wantError bool
	}{
		{
			name:      "valid language - en",
			language:  "en",
			wantError: false,
		},
		{
			name:      "valid language - fr",
			language:  "fr",
			wantError: false,
		},
		{
			name:      "valid language - es",
			language:  "es",
			wantError: false,
		},
		{
			name:      "valid language - de",
			language:  "de",
			wantError: false,
		},
		{
			name:      "valid language - zh",
			language:  "zh",
			wantError: false,
		},
		{
			name:      "empty language - should pass",
			language:  "",
			wantError: false,
		},
		{
			name:      "invalid language - xx",
			language:  "xx",
			wantError: true,
		},
		{
			name:      "invalid language - invalid",
			language:  "invalid",
			wantError: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := ValidateLanguage(tt.language)
			if tt.wantError {
				assert.Error(t, err)
				assert.Contains(t, err.Error(), "unsupported language code")
			} else {
				assert.NoError(t, err)
			}
		})
	}
}

func TestValidateTimezone(t *testing.T) {
	tests := []struct {
		name      string
		timezone  string
		wantError bool
	}{
		{
			name:      "valid timezone - UTC",
			timezone:  "UTC",
			wantError: false,
		},
		{
			name:      "valid timezone - America/New_York",
			timezone:  "America/New_York",
			wantError: false,
		},
		{
			name:      "valid timezone - Europe/Paris",
			timezone:  "Europe/Paris",
			wantError: false,
		},
		{
			name:      "valid timezone - Asia/Tokyo",
			timezone:  "Asia/Tokyo",
			wantError: false,
		},
		{
			name:      "empty timezone - should pass",
			timezone:  "",
			wantError: false,
		},
		{
			name:      "invalid timezone - Invalid/Timezone",
			timezone:  "Invalid/Timezone",
			wantError: true,
		},
		{
			name:      "invalid timezone - not-a-timezone",
			timezone:  "not-a-timezone",
			wantError: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := ValidateTimezone(tt.timezone)
			if tt.wantError {
				assert.Error(t, err)
				assert.Contains(t, err.Error(), "invalid timezone")
			} else {
				assert.NoError(t, err)
			}
		})
	}
}

func TestValidateTheme(t *testing.T) {
	tests := []struct {
		name      string
		theme     string
		wantError bool
	}{
		{
			name:      "valid theme - light",
			theme:     "light",
			wantError: false,
		},
		{
			name:      "valid theme - dark",
			theme:     "dark",
			wantError: false,
		},
		{
			name:      "valid theme - auto",
			theme:     "auto",
			wantError: false,
		},
		{
			name:      "empty theme - should pass",
			theme:     "",
			wantError: false,
		},
		{
			name:      "invalid theme - invalid",
			theme:     "invalid",
			wantError: true,
		},
		{
			name:      "invalid theme - light-dark",
			theme:     "light-dark",
			wantError: true,
		},
		{
			name:      "invalid theme - LIGHT (case sensitive)",
			theme:     "LIGHT",
			wantError: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := ValidateTheme(tt.theme)
			if tt.wantError {
				assert.Error(t, err)
				assert.Contains(t, err.Error(), "invalid theme")
			} else {
				assert.NoError(t, err)
			}
		})
	}
}

func TestSupportedLanguages(t *testing.T) {
	// Test that all expected languages are in the list
	expectedLanguages := []string{"en", "fr", "es", "de", "it", "pt", "ru", "ja", "zh", "ko"}
	for _, lang := range expectedLanguages {
		found := false
		for _, supported := range SupportedLanguages {
			if supported == lang {
				found = true
				break
			}
		}
		assert.True(t, found, "Language %s should be in SupportedLanguages", lang)
	}
}

func TestSupportedThemes(t *testing.T) {
	// Test that all expected themes are in the list
	expectedThemes := []string{"light", "dark", "auto"}
	for _, theme := range expectedThemes {
		found := false
		for _, supported := range SupportedThemes {
			if supported == theme {
				found = true
				break
			}
		}
		assert.True(t, found, "Theme %s should be in SupportedThemes", theme)
	}
}
