package app.closer.domain.model

data class QuestionThread(
    val id: String = "",
    val coupleId: String = "",
    val questionId: String = "",
    val categoryId: String = "",
    val status: QuestionThreadStatus = QuestionThreadStatus.NOT_STARTED,
    val currentIndex: Int = 0,
    val createdAt: Long = 0L,
    val updatedAt: Long = 0L
)

enum class QuestionThreadStatus {
    NOT_STARTED,
    ANSWERED_BY_ONE,
    REVEALED,
    COMPLETED;

    // Stored UPPERCASE to match the Firestore rules' status-transition checks
    // (NOT_STARTED → ANSWERED_BY_ONE → REVEALED → COMPLETED). Lowercase here meant every
    // status update was rejected, which broke the discussion thread. Reads tolerate both cases.
    fun toFirestoreValue(): String = name

    companion object {
        fun fromFirestoreValue(value: String): QuestionThreadStatus = when (value.uppercase()) {
            "ANSWERED_BY_ONE" -> ANSWERED_BY_ONE
            "REVEALED" -> REVEALED
            "COMPLETED" -> COMPLETED
            else -> NOT_STARTED
        }
    }
}
