package com.correx.core.events.events

import com.correx.core.events.types.SessionId
import com.correx.core.inference.TokenUsage
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
@SerialName("ChatTurn")
data class ChatTurnEvent(
    val sessionId: SessionId,
    val turnId: String,
    val role: ChatTurnRole,
    val content: String,
    val timestampMs: Long,
    val latencyMs: Long? = null,
    val tokensUsed: TokenUsage? = null,
) : EventPayload

@Serializable
enum class ChatTurnRole {
    USER,
    ROUTER,
}

@Serializable
@SerialName("L3MemoryRetrieved")
data class L3MemoryRetrievedEvent(
    val sessionId: SessionId,
    val queryTurnId: String,
    val hits: List<L3RetrievedHit>,
    val timestampMs: Long,
) : EventPayload

@Serializable
data class L3RetrievedHit(
    val entryId: String,
    val sourceSessionId: SessionId,
    val sourceTurnId: String,
    val text: String,
    val score: Float,
)

@Serializable
@SerialName("ContextTruncated")
data class ContextTruncatedEvent(
    val sessionId: SessionId,
    val turnId: String,
    val entriesDropped: Int,
    val truncatedLayers: List<String>,
    val timestampMs: Long,
) : EventPayload

@Serializable
@SerialName("RouterNarration")
data class TalkieNarrationEvent(
    val sessionId: SessionId,
    val narrationId: String,
    val trigger: String,
    val stageId: String? = null,
    val content: String,
    val latencyMs: Long? = null,
    val tokensUsed: TokenUsage? = null,
    val timestampMs: Long,
) : EventPayload
