package com.correx.core.events.serialization

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

class RefinementEventSerializationTest {

    @Test
    fun `RefinementIterationEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = RefinementIterationEvent(
            sessionId = SessionId("s"),
            cycleKey = "implement->review",
            iteration = 2,
            maxIterations = 3,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"RefinementIteration\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
