package app.closer.domain.repository

import app.closer.domain.model.QuestionSession
import kotlinx.coroutines.flow.Flow

interface QuestionSessionRepository {
    /** Saves the session and returns its (possibly auto-generated) document id. */
    suspend fun saveSession(session: QuestionSession): Result<String>
    suspend fun getSessionsForCouple(coupleId: String): Result<List<QuestionSession>>
    
    // Active session queries
    suspend fun getActiveSessionForCouple(coupleId: String): QuestionSession?
    fun observeActiveSessionForCouple(coupleId: String): Flow<QuestionSession?>
    suspend fun hasActiveSession(coupleId: String): Boolean

    // Per-user completion: marks one user done; auto-completes when both users are recorded.
    suspend fun markUserComplete(sessionId: String, coupleId: String, userId: String): Result<Unit>

    // Force-complete the active session (escape hatch for stuck/abandoned games).
    suspend fun abandonSession(coupleId: String): Result<Unit>

    // Single-session lookup by ID (for history replay).
    suspend fun getSessionById(coupleId: String, sessionId: String): QuestionSession?
}
