package com.correx.core.events.serialization

import com.correx.core.events.events.EventPayload
import com.correx.core.events.events.ReviewFinding
import com.correx.core.events.events.ReviewFindingsRaisedEvent
import com.correx.core.events.events.ReviewSeverity
import com.correx.core.events.events.ReviewVerdict
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.assertTrue

class ReviewFindingsRaisedEventSerializationTest {

    @Test
    fun `ReviewFindingsRaisedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = ReviewFindingsRaisedEvent(
            sessionId = SessionId("s"),
            stageId = StageId("implement"),
            verdict = ReviewVerdict.FAIL,
            findings = listOf(
                ReviewFinding(
                    severity = ReviewSeverity.CRITICAL,
                    confidence = 0.9,
                    category = "correctness",
                    target = "src/App.tsx:42",
                    message = "off-by-one in the loop bound",
                    suggestedFix = "use < instead of <=",
                    correctness = true,
                ),
            ),
            blocked = true,
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"ReviewFindingsRaised\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
