package com.correx.core.events.serialization

import com.correx.core.events.events.ContextAssembledEvent
import com.correx.core.events.events.ContextManifestEntry
import com.correx.core.events.events.EventPayload
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

class ContextAssembledEventSerializationTest {

    @Test
    fun `ContextAssembledEvent round-trips through eventModule`() {
        val sample: EventPayload = ContextAssembledEvent(
            sessionId = SessionId("s"),
            stageId = StageId("implement"),
            contextPackId = "pack-1",
            entries = listOf(
                ContextManifestEntry(
                    sourceType = "conceptPromotion",
                    sourceId = "concept-42",
                    tokenEstimate = 120,
                    layer = "L0",
                    role = "SYSTEM",
                ),
            ),
            timestampMs = 1_700_000_000_000L,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertEquals(sample, eventJson.decodeFromString(EventPayload.serializer(), encoded))
    }

    @Test
    fun `ContextAssembledEvent manifest never carries entry content`() {
        val sample: EventPayload = ContextAssembledEvent(
            sessionId = SessionId("s"),
            stageId = StageId("implement"),
            contextPackId = "pack-1",
            entries = listOf(
                ContextManifestEntry(
                    sourceType = "steering",
                    sourceId = "note-1",
                    tokenEstimate = 5,
                    layer = "L0",
                    role = "USER",
                ),
            ),
            timestampMs = 0L,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertFalse(encoded.contains("\"content\""), "manifest must not carry entry content: $encoded")
    }
}
