package solutions.tretter.mindmachine

import solutions.tretter.mindmachine.domain.RuntimeState
import solutions.tretter.mindmachine.session.sessionProgressFraction
import solutions.tretter.mindmachine.session.shouldRevealSystemBarsOnTap
import solutions.tretter.mindmachine.session.shouldShowActiveControlsByDefault
import solutions.tretter.mindmachine.session.shouldUseImmersiveFullscreen
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class ActiveSessionUiTest {
    @Test
    fun controls_are_hidden_by_default_while_counting_down_or_running() {
        assertFalse(shouldShowActiveControlsByDefault(RuntimeState.COUNTDOWN))
        assertFalse(shouldShowActiveControlsByDefault(RuntimeState.RUNNING))
    }

    @Test
    fun controls_are_visible_by_default_when_not_actively_stimulating() {
        assertTrue(shouldShowActiveControlsByDefault(RuntimeState.IDLE))
        assertTrue(shouldShowActiveControlsByDefault(RuntimeState.PAUSED))
        assertTrue(shouldShowActiveControlsByDefault(RuntimeState.INTERRUPTED))
        assertTrue(shouldShowActiveControlsByDefault(RuntimeState.COMPLETED))
        assertTrue(shouldShowActiveControlsByDefault(RuntimeState.STOPPED))
    }

    @Test
    fun immersive_fullscreen_applies_only_to_visual_countdown_and_running_states() {
        assertTrue(shouldUseImmersiveFullscreen(isVisualMode = true, runtimeState = RuntimeState.COUNTDOWN))
        assertTrue(shouldUseImmersiveFullscreen(isVisualMode = true, runtimeState = RuntimeState.RUNNING))

        assertFalse(shouldUseImmersiveFullscreen(isVisualMode = false, runtimeState = RuntimeState.COUNTDOWN))
        assertFalse(shouldUseImmersiveFullscreen(isVisualMode = false, runtimeState = RuntimeState.RUNNING))
        assertFalse(shouldUseImmersiveFullscreen(isVisualMode = true, runtimeState = RuntimeState.PAUSED))
        assertFalse(shouldUseImmersiveFullscreen(isVisualMode = true, runtimeState = RuntimeState.INTERRUPTED))
    }

    @Test
    fun tap_to_reveal_system_bars_is_disabled() {
        assertFalse(shouldRevealSystemBarsOnTap(isVisualMode = true, runtimeState = RuntimeState.COUNTDOWN))
        assertFalse(shouldRevealSystemBarsOnTap(isVisualMode = true, runtimeState = RuntimeState.RUNNING))
        assertFalse(shouldRevealSystemBarsOnTap(isVisualMode = false, runtimeState = RuntimeState.RUNNING))
        assertFalse(shouldRevealSystemBarsOnTap(isVisualMode = true, runtimeState = RuntimeState.PAUSED))
        assertFalse(shouldRevealSystemBarsOnTap(isVisualMode = true, runtimeState = RuntimeState.COMPLETED))
    }

    @Test
    fun session_progress_fraction_tracks_elapsed_time_and_clamps() {
        assertTrue(sessionProgressFraction(durationSec = 600, remainingSec = 600) == 0f)
        assertTrue(sessionProgressFraction(durationSec = 600, remainingSec = 300) == 0.5f)
        assertTrue(sessionProgressFraction(durationSec = 600, remainingSec = 0) == 1f)
        assertTrue(sessionProgressFraction(durationSec = 600, remainingSec = 800) == 0f)
        assertTrue(sessionProgressFraction(durationSec = 600, remainingSec = -10) == 1f)
    }

}
