package app.closer.domain.model

/**
 * Manual test flow:
 *  1. Pair two test users. Open Settings → Your Progress. Baseline should be empty.
 *  2. Submit baseline from either member via outcome dialog. Return to Your Progress; baseline shown.
 *  3. Submit follow-up day_30 outcome. Deltas should compute against baseline.
 *  4. Verify invalid dayKey or out-of-range scores rejected by callable.
 */

typealias OutcomeDayKey = String

enum class OutcomeDay(val key: OutcomeDayKey, val label: String) {
    BASELINE("day_0", "Baseline"),
    DAY_30("day_30", "30-day"),
    DAY_60("day_60", "60-day"),
    DAY_90("day_90", "90-day");

    companion object {
        fun fromKey(key: OutcomeDayKey): OutcomeDay? = entries.firstOrNull { it.key == key }
    }
}

data class OutcomeScores(
    val connection: Int,
    val communication: Int,
    val intimacy: Int,
    val happiness: Int
) {
    init {
        require(connection in 1..10) { "connection must be 1-10" }
        require(communication in 1..10) { "communication must be 1-10" }
        require(intimacy in 1..10) { "intimacy must be 1-10" }
        require(happiness in 1..10) { "happiness must be 1-10" }
    }

    fun toMap(): Map<String, Int> = mapOf(
        "connection" to connection,
        "communication" to communication,
        "intimacy" to intimacy,
        "happiness" to happiness
    )
}

data class Outcome(
    val dayKey: OutcomeDayKey,
    val baseline: OutcomeScores? = null,
    val scores: OutcomeScores? = null,
    val delta: OutcomeScores? = null,
    val answeredBy: List<String> = emptyList(),
    val createdAt: Long? = null,
    val updatedAt: Long? = null
)
