package com.correx.core.events.events

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

/**
 * First-class record of a file mutation performed by a tool. Makes file writes
 * reversible from the log + CAS (invariants #1/#5): [preImageHash]/[postImageHash]
 * are content-addressed blobs in the ArtifactStore. A newly-created file has
 * `preExisted = false` and a null [preImageHash]; a delete has a null
 * [postImageHash]. Undo restores the pre-image blob (or deletes) through the
 * same atomic write seam.
 */
@Serializable
@SerialName("FileWritten")
data class FileWrittenEvent(
    val invocationId: ToolInvocationId,
    val sessionId: SessionId,
    val path: String,
    val preImageHash: String? = null,
    val postImageHash: String? = null,
    val preExisted: Boolean,
    val mode: String = "0644",
    val timestampMs: Long,
) : EventPayload
