package dev.kaizen.app

import dev.kaizen.app.settings.AppAppearance
import dev.kaizen.app.settings.SettingsViewModel
import dev.kaizen.app.ui.theme.themes.KaizenThemeId
import org.junit.Assert.assertEquals
import org.junit.Test

class SettingsViewModelTest {

    @Test
    fun testInitialState() {
        val viewModel = SettingsViewModel()
        assertEquals(KaizenThemeId.AMBER, viewModel.selectedTheme.value)
        assertEquals(AppAppearance.System, viewModel.appearanceMode.value)
        assertEquals("", viewModel.userName.value)
    }

    @Test
    fun testSelectTheme() {
        val viewModel = SettingsViewModel()
        viewModel.selectTheme(KaizenThemeId.AURORA)
        assertEquals(KaizenThemeId.AURORA, viewModel.selectedTheme.value)
    }

    @Test
    fun testSelectAllThemes() {
        val viewModel = SettingsViewModel()
        KaizenThemeId.entries.forEach { id ->
            viewModel.selectTheme(id)
            assertEquals(id, viewModel.selectedTheme.value)
        }
    }

    @Test
    fun testSelectAppearance() {
        val viewModel = SettingsViewModel()
        viewModel.selectAppearance(AppAppearance.Light)
        assertEquals(AppAppearance.Light, viewModel.appearanceMode.value)
    }

    @Test
    fun testUpdateUserName() {
        val viewModel = SettingsViewModel()
        viewModel.updateUserName("  Giuseppe  ")
        assertEquals("Giuseppe", viewModel.userName.value)
    }

    @Test
    fun testUpdateUserNameBlankIgnored() {
        val viewModel = SettingsViewModel()
        viewModel.updateUserName("Bruno")
        viewModel.updateUserName("   ")
        assertEquals("Bruno", viewModel.userName.value)
    }
}
