package com.dano.test1.scoring

import com.dano.test1.network.ScoringProfileDefinition
import com.dano.test1.network.ScoringProfileMember
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class ProfileScoringEngineTest {

    private val profile = ScoringProfileDefinition(
        profileID = "p1",
        name = "RHS Index",
        greenMin = 0,
        greenMax = 12,
        yellowMin = 13,
        yellowMax = 36,
        redMin = 37,
        questionnaires = listOf(
            ScoringProfileMember(questionnaireID = "qn_a", weight = 1.0),
            ScoringProfileMember(questionnaireID = "qn_b", weight = 2.0),
        ),
    )

    @Test
    fun bandForTotal_matchesServerThresholds() {
        assertEquals("green", ProfileScoringEngine.bandForTotal(0.0, profile))
        assertEquals("green", ProfileScoringEngine.bandForTotal(12.0, profile))
        assertEquals("yellow", ProfileScoringEngine.bandForTotal(13.0, profile))
        assertEquals("yellow", ProfileScoringEngine.bandForTotal(36.0, profile))
        assertEquals("red", ProfileScoringEngine.bandForTotal(37.0, profile))
    }

    @Test
    fun computeProfile_weightedSum() {
        val result = ProfileScoringEngine.computeProfile(
            profile,
            mapOf("qn_a" to 5, "qn_b" to 4),
            setOf("qn_a", "qn_b"),
        )
        requireNotNull(result)
        assertEquals(13.0, result.weightedTotal, 0.0001)
        assertEquals("yellow", result.calculatedBand)
    }

    @Test
    fun computeProfile_incompleteWhenMemberMissing() {
        assertNull(
            ProfileScoringEngine.computeProfile(
                profile,
                mapOf("qn_a" to 5),
                setOf("qn_a"),
            ),
        )
    }
}
