package com.correx.core.events.events

import com.correx.core.events.types.ArtifactId
import com.correx.core.events.types.InferenceRequestId
import com.correx.core.events.types.ProviderId
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.inference.TokenUsage
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


@Serializable
@SerialName("InferenceStarted")
data class InferenceStartedEvent(
    val requestId: InferenceRequestId,
    val sessionId: SessionId,
    val stageId: StageId,
    val providerId: ProviderId,
    val promptArtifactId: ArtifactId,
) : EventPayload

@Serializable
@SerialName("InferenceCompleted")
data class InferenceCompletedEvent(
    val requestId: InferenceRequestId,
    val sessionId: SessionId,
    val stageId: StageId,
    val providerId: ProviderId,
    val tokensUsed: TokenUsage,
    val latencyMs: Long,
    val responseArtifactId: ArtifactId,
    val reasoningArtifactId: ArtifactId? = null,
) : EventPayload

@Serializable
@SerialName("InferenceFailed")
data class InferenceFailedEvent(
    val requestId: InferenceRequestId,
    val sessionId: SessionId,
    val stageId: StageId,
    val providerId: ProviderId,
    val reason: String,           // human-readable; structured cause lives in CancellationReason
) : EventPayload

@Serializable
@SerialName("InferenceTimeout")
data class InferenceTimeoutEvent(
    val requestId: InferenceRequestId,
    val sessionId: SessionId,
    val stageId: StageId,
    val providerId: ProviderId,
    val timeoutMs: Long,
) : EventPayload

@Serializable
@SerialName("ModelLoaded")
data class ModelLoadedEvent(
    val modelId: String,
    val providerId: ProviderId,
    val sessionId: SessionId,
) : EventPayload

@Serializable
@SerialName("ModelUnloaded")
data class ModelUnloadedEvent(
    val modelId: String,
    val providerId: ProviderId,
    val sessionId: SessionId,
    val cancellationReason: String? = null,  // serialized label, not the sealed class
) : EventPayload
