package com.correx.core.talkie.model

import com.correx.core.events.events.L3RetrievedHit
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
enum class WorkflowStatus {
    IDLE,
    RUNNING,
    PAUSED,
    COMPLETED,
    FAILED,
}

@Serializable
enum class StageOutcomeKind {
    SUCCESS,
    FAILURE,
    CANCELLED,
}

@Serializable
enum class TurnRole {
    USER,
    ROUTER,
}

@Serializable
data class RouterL2Entry(
    val stageId: StageId,
    val summary: String,
    val outcome: StageOutcomeKind,
    val timestamp: Instant,
    /** Failure reason, when [outcome] is FAILURE. */
    val reason: String? = null,
    /** User steering notes issued during this stage (adr-0003 §4 decision-point harvest). */
    val steeringNotes: List<String> = emptyList(),
)

@Serializable
data class TalkieTurn(
    val role: TurnRole,
    val content: String,
    val timestamp: Instant,
    val turnId: String = "",
)

@Serializable
data class TalkieState(
    val sessionId: SessionId? = null,
    val workflowStatus: WorkflowStatus = WorkflowStatus.IDLE,
    val currentStageId: StageId? = null,
    val l2Memory: List<RouterL2Entry> = emptyList(),
    val conversationHistory: List<TalkieTurn> = emptyList(),
    val lastRetrievedMemory: List<L3RetrievedHit> = emptyList(),
    /**
     * Steering notes accumulated during the current stage, harvested into the
     * stage's [RouterL2Entry] when it completes or fails, then cleared.
     */
    val pendingSteeringNotes: List<String> = emptyList(),
)
