package com.correx.core.events.serialization

import com.correx.core.events.events.EventPayload
import com.correx.core.events.events.PossibleContradictionFlaggedEvent
import com.correx.core.events.events.RelatedDecision
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 ContradictionEventSerializationTest {

    @Test
    fun `PossibleContradictionFlaggedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = PossibleContradictionFlaggedEvent(
            sessionId = SessionId("s"),
            stageId = StageId("architect"),
            decisionSummary = "Use Postgres for the event store.",
            related = listOf(
                RelatedDecision(
                    summary = "Decided to use SQLite for the event store.",
                    score = 0.91,
                    source = "project:/repo",
                ),
            ),
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(
            encoded.contains("\"type\":\"PossibleContradictionFlagged\""),
            "SerialName must be present: $encoded",
        )
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
