package space.nstart.pcp.pcp_types_lib.dto.satellite.mission

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertInstanceOf
import org.junit.jupiter.api.Test

class ModeResponseDTOJacksonTest {

    private val mapper = jacksonObjectMapper().registerModule(JavaTimeModule())

    @Test
    fun `deserializes mixed mission modes by type`() {
        val json = """
            [
              {
                "id": 1,
                "planId": 10,
                "timeStart": "2026-03-17T08:00:00Z",
                "revolution": 100,
                "type": "SURVEY",
                "source": "AUTO",
                "lat": 55.75,
                "longitude": 37.62,
                "duration": 12.5,
                "contourWkt": null,
                "roll": 1.5,
                "bookedSlotIds": [101, 102]
              },
              {
                "id": 2,
                "planId": 10,
                "timeStart": "2026-03-17T09:00:00Z",
                "revolution": 101,
                "type": "DROP",
                "station": "S1",
                "duration": 3.0,
                "surveys": [1]
              }
            ]
        """.trimIndent()

        val result: List<ModeResponseDTO> = mapper.readValue(json)

        assertEquals(2, result.size)
        assertInstanceOf(SurveyModeResponseDTO::class.java, result[0])
        assertInstanceOf(DropModeResponseDTO::class.java, result[1])
        assertEquals("SURVEY", result[0].type)
        assertEquals("DROP", result[1].type)
    }
}
