package com.correx.core.events.serialization

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

class ConceptPromotedEventSerializationTest {

    private val sample = ConceptPromotedEvent(
        sessionId = SessionId("__concept_compiler__"),
        fingerprint = "1a2b3c",
        gate = "lint",
        conceptText = "Recurring lint failure (validated-fixed 3x across sessions): detekt: MagicNumber.",
        occurrences = 3,
    )

    @Test
    fun `round-trips as polymorphic EventPayload`() {
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"ConceptPromoted\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
