package com.correx.core.events.events

import com.correx.core.approvals.Tier
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.events.types.ToolInvocationId
import com.correx.core.tools.contract.ToolCapability
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
@SerialName("ToolExecutionCompleted")
data class ToolExecutionCompletedEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val toolName: String,
    val receipt: ToolReceipt,
) : EventPayload

@Serializable
@SerialName("ToolExecutionFailed")
data class ToolExecutionFailedEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val toolName: String,
    val reason: String,
) : EventPayload

@Serializable
@SerialName("ToolExecutionRejected")
data class ToolExecutionRejectedEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val toolName: String,
    val tier: Tier,
    val reason: String,
) : EventPayload

@Serializable
@SerialName("ToolExecutionStarted")
data class ToolExecutionStartedEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val toolName: String,
) : EventPayload

@Serializable
@SerialName("ToolInvocationRequested")
data class ToolInvocationRequestedEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val stageId: StageId,
    val toolName: String,
    val tier: Tier,
    val request: ToolRequest,
    // The tool's declared capabilities, recorded at emission so replay classifies the call by what
    // it could actually do (e.g. FILE_READ/FILE_WRITE) without re-deriving from the live registry.
    // Defaulted for backward compatibility: events written before this field deserialize as empty.
    val capabilities: Set<ToolCapability> = emptySet(),
) : EventPayload

@Serializable
@SerialName("ToolInvoked")
data class ToolInvokedEvent(
    val toolId: String,
) : EventPayload
