package com.correx.core.events.serialization

import com.correx.core.events.events.EgressHostsGrantedEvent
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 EgressEventSerializationTest {

    @Test
    fun `EgressHostsGrantedEvent round-trips as polymorphic EventPayload`() {
        val sample: EventPayload = EgressHostsGrantedEvent(
            sessionId = SessionId("s"),
            hosts = setOf("example.com", "docs.rust-lang.org"),
            reason = "approved research source list",
        )
        val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
        assertTrue(encoded.contains("\"type\":\"EgressHostsGranted\""), "SerialName must be present: $encoded")
        val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
        assertEquals(sample, decoded)
    }
}
