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

/**
 * A research T2 fetch completed and produced content at [contentSha256] (research-workflow-spec §3/§5).
 *
 * Promotes the fetch-quality + content-hash that previously lived only inside
 * [ToolExecutionCompletedEvent] metadata into a first-class event, so "what sources were fetched"
 * is queryable and renderable directly from the journal. Additive: the metadata write is retained
 * for existing consumers. [quality] mirrors the extractor's quality marker as recorded in metadata.
 */
@Serializable
@SerialName("SourceFetched")
data class SourceFetchedEvent(
    val sessionId: SessionId,
    val stageId: StageId,
    val url: String,
    val contentSha256: String,
    val quality: String,
    val byteCount: Int = 0,
) : EventPayload

/**
 * An extraction was retained but flagged low-quality — below the quality bar (research-workflow-spec §5)
 * — for operator visibility. Emitted alongside [SourceFetchedEvent] when the fetch cleared rejection
 * but fell under the minimum-content threshold (JS-rendered SPA, paywall); the content is still kept,
 * the operator is simply warned that synthesis may want to route around it.
 */
@Serializable
@SerialName("LowQualityExtraction")
data class LowQualityExtractionEvent(
    val sessionId: SessionId,
    val stageId: StageId,
    val url: String,
    val contentSha256: String,
    val reason: String,
) : EventPayload
