package com.correx.core.events.serialization

import com.correx.core.events.events.ArtifactRepairAttemptedEvent
import com.correx.core.events.events.ArtifactRepairFailedEvent
import com.correx.core.events.events.ArtifactRepairResolvedEvent
import com.correx.core.events.events.EventPayload
import com.correx.core.events.types.ArtifactId
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import kotlin.test.Test
import kotlin.test.assertEquals

class ArtifactRepairEventSerializationTest {

    private fun roundTrip(sample: EventPayload) =
        assertEquals(sample, eventJson.decodeFromString(EventPayload.serializer(),
            eventJson.encodeToString(EventPayload.serializer(), sample)))

    @Test
    fun `ArtifactRepairAttempted round-trips`() {
        roundTrip(ArtifactRepairAttemptedEvent(ArtifactId("a"), "SCHEMA", "LLM", SessionId("s"), StageId("st")))
    }

    @Test
    fun `ArtifactRepairResolved round-trips`() {
        roundTrip(ArtifactRepairResolvedEvent(ArtifactId("a"), ArtifactId("hash"), SessionId("s"), StageId("st")))
    }

    @Test
    fun `ArtifactRepairFailed round-trips`() {
        roundTrip(
            ArtifactRepairFailedEvent(
                ArtifactId("a"), "UNSAFE", "Abort", "path escapes", SessionId("s"), StageId("st"),
            ),
        )
    }
}
