package com.correx.core.events.serialization

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

class ExecutionPlanRejectedEventSerializationTest {

    @Test
    fun `ExecutionPlanRejectedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = ExecutionPlanRejectedEvent(
            sessionId = SessionId("s"),
            reason = "plan failed to compile: Unknown artifact kind",
            source = "compile",
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"ExecutionPlanRejected\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
