package com.correx.core.events.events

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

/** A single ranked entry in a repo map: a path, its relevance [score], and symbol names. */
@Serializable
data class RepoMapEntry(
    val path: String,
    val score: Double,
    val symbols: List<String> = emptyList(),
    /** Bounded deterministic source-purpose text used for semantic repo retrieval. */
    val descriptor: String = "",
)

/**
 * Workspace content-state observed at session start (invariant #9). stateKey identifies the
 * exact content state: "git:<HEAD>" for a clean git worktree, "fp:<sha256>" (stat-only
 * fingerprint) for dirty or non-git workspaces. Downstream reuse decisions read this event,
 * never re-probe the environment.
 */
@Serializable
@SerialName("WorkspaceStateObserved")
data class WorkspaceStateObservedEvent(
    val sessionId: SessionId,
    val workspaceRoot: String,
    val stateKey: String,
    val source: String,
    val branch: String? = null,
    val dirty: Boolean = false,
) : EventPayload

/**
 * Environment observation (invariant #9): the repo map computed once at the moment it ran.
 * Replay reads these recorded facts and never re-scans the filesystem. Paths + symbol names
 * only — never file bodies — so it is referenced, not inlined.
 */
@Serializable
@SerialName("RepoMapComputed")
data class RepoMapComputedEvent(
    val sessionId: SessionId,
    val repoRoot: String,
    val entries: List<RepoMapEntry>,
    val computedAt: Instant,
    val stateKey: String? = null,
) : EventPayload
