package com.correx.core.events.events

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

/**
 * Per-stage reconciliation of a stage's produced artifacts against the locked plan's produces-slots,
 * recorded so plan adherence is observable and replayable. Emitted only on plan-driven (phase-2)
 * runs — a session whose log contains an [ExecutionPlanLockedEvent]; non-plan workflows emit nothing.
 *
 * The *passed* variant means every expected slot was produced: [producedArtifacts] is a superset of
 * [expectedArtifacts] (extra artifacts beyond the expected set do not fail the checkpoint).
 */
@Serializable
@SerialName("StageCheckpointPassed")
data class StageCheckpointPassedEvent(
    val sessionId: SessionId,
    val stageId: StageId,
    val expectedArtifacts: Set<String>,
    val producedArtifacts: Set<String>,
) : EventPayload

/**
 * Per-stage reconciliation of a stage's produced artifacts against the locked plan's produces-slots,
 * recorded so plan adherence is observable and replayable. Emitted only on plan-driven (phase-2)
 * runs — a session whose log contains an [ExecutionPlanLockedEvent]; non-plan workflows emit nothing.
 *
 * The *failed* variant accompanies the stage halt owned by `verifyProduces` and surfaces *why* the
 * plan diverged: [missingArtifacts] are the expected slots ([expectedArtifacts] minus
 * [producedArtifacts]) the stage never produced.
 */
@Serializable
@SerialName("StageCheckpointFailed")
data class StageCheckpointFailedEvent(
    val sessionId: SessionId,
    val stageId: StageId,
    val expectedArtifacts: Set<String>,
    val producedArtifacts: Set<String>,
    val missingArtifacts: Set<String>,
) : EventPayload
