package solutions.tretter.mindmachine

import solutions.tretter.mindmachine.domain.SessionConfig
import solutions.tretter.mindmachine.domain.SessionMode
import solutions.tretter.mindmachine.domain.VisualPattern
import solutions.tretter.mindmachine.session.SessionValidator
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class SessionValidatorTest {
    private val valid = SessionConfig(
        presetId = "relax",
        durationSec = 600,
        mode = SessionMode.AUDIO_VISUAL,
        visualPatternType = VisualPattern.PULSE,
        flashIntervalMs = 167,
        intensityPercent = 50,
        carrierFrequencyHz = 200f,
        binauralDifferenceHz = 6f,
    )

    @Test
    fun valid_config_passes() {
        assertNull(SessionValidator.validate(valid))
    }

    @Test
    fun out_of_range_values_are_blocked() {
        assertEquals("Duration must be 1 minute to 60 minutes.", SessionValidator.validate(valid.copy(durationSec = 59)))
        assertEquals("Flash interval must be 0.05 to 2.00 seconds.", SessionValidator.validate(valid.copy(flashIntervalMs = 49)))
        assertEquals("Carrier frequency must be between 200 and 1200 Hz.", SessionValidator.validate(valid.copy(carrierFrequencyHz = 0f)))
        assertEquals("Carrier frequency must be between 200 and 1200 Hz.", SessionValidator.validate(valid.copy(carrierFrequencyHz = 20001f)))
        assertEquals("Binaural difference must be between 0.5 and 20.", SessionValidator.validate(valid.copy(binauralDifferenceHz = 0.1f)))
    }
}
