package com.correx.core.events.serialization

import com.correx.core.events.events.EventPayload
import com.correx.core.events.events.ExecutionPlanLockedEvent
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 ExecutionPlanLockedEventSerializationTest {

    @Test
    fun `ExecutionPlanLockedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = ExecutionPlanLockedEvent(
            sessionId = SessionId("s"),
            planArtifactId = ArtifactId("execution_plan"),
            workflowId = "freestyle-s",
            stageIds = listOf("impl", "review"),
            startStageId = "impl",
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"ExecutionPlanLocked\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
