package com.correx.core.events.serialization

import com.correx.core.events.events.CritiqueOutcome
import com.correx.core.events.events.CritiqueOutcomeCorrelatedEvent
import com.correx.core.events.events.CritiqueRole
import com.correx.core.events.events.CritiqueSeverity
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 CritiqueCalibrationEventSerializationTest {

    @Test
    fun `CritiqueOutcomeCorrelatedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = CritiqueOutcomeCorrelatedEvent(
            sessionId = SessionId("s"),
            findingId = "f-1",
            role = CritiqueRole.CODE_REVIEWER,
            modelHash = "sha256:abc",
            severity = CritiqueSeverity.MAJOR,
            outcome = CritiqueOutcome.UPHELD,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(
            encoded.contains("\"type\":\"CritiqueOutcomeCorrelated\""),
            "SerialName must be present: $encoded",
        )
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
