package com.correx.core.events.serialization

import com.correx.core.events.events.EventPayload
import com.correx.core.events.events.JournalCompactedEvent
import com.correx.core.events.types.ArtifactId
import com.correx.core.events.types.SessionId
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class JournalCompactedEventSerializationTest {

    @Test
    fun `JournalCompactedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = JournalCompactedEvent(
            sessionId = SessionId("s1"),
            coversThroughSequence = 42L,
            summaryArtifactId = ArtifactId("summary-1"),
            lowSalienceOmittedCount = 7,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"JournalCompacted\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
