package com.correx.core.events.serialization

import com.correx.core.events.events.LspDiagnostic
import com.correx.core.events.events.LspDiagnosticsCompletedEvent
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.assertIs

class LspDiagnosticsCompletedEventSerializationTest {
    @Test
    fun `round-trips as polymorphic EventPayload`() {
        val event = LspDiagnosticsCompletedEvent(
            SessionId("s"), StageId("impl"), "tsserver",
            listOf(LspDiagnostic("src/App.tsx", 1, 2, "error", "2322", "not assignable")),
        )
        val encoded = eventJson.encodeToString(com.correx.core.events.events.EventPayload.serializer(), event)
        val decoded = eventJson.decodeFromString(com.correx.core.events.events.EventPayload.serializer(), encoded)
        assertIs<LspDiagnosticsCompletedEvent>(decoded)
        assertEquals("src/App.tsx", decoded.diagnostics.single().path)
    }
}
