package org.nstart.dep265.requestservice.dto

import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test
import java.time.LocalDateTime
import java.util.UUID

/**
 * Контракт формата времени на проводе для [RequestResponseDto]: naive `LocalDateTime` → ISO без зоны
 * (напр. `"2026-05-29T01:00:00"`). Тест ловит случайный возврат к OffsetDateTime/Z или числовым меткам.
 */
class RequestResponseDtoContractTest {

    private val mapper = jacksonObjectMapper().findAndRegisterModules()
        .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

    @Test
    fun `serializes request times as naive ISO without zone`() {
        val dto = RequestResponseDto(
            id = UUID.fromString("00000000-0000-0000-0000-000000000001"),
            name = "request",
            status = RequestStatusDto.ACTIVE,
            surveyType = SurveyTypeDto.OPTICS,
            geometry = "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
            importance = 1.0,
            beginDateTime = LocalDateTime.of(2026, 5, 29, 1, 0, 0),
            endDateTime = LocalDateTime.of(2026, 5, 29, 2, 0, 0),
            highPriorityTransmit = false,
            coverage = CoverageStateDto(currentPercent = 0.0),
            createdAt = LocalDateTime.of(2026, 5, 29, 0, 0, 0),
            updatedAt = LocalDateTime.of(2026, 5, 29, 0, 0, 0)
        )

        val node = mapper.readTree(mapper.writeValueAsString(dto))

        assertEquals("2026-05-29T01:00:00", node.get("beginDateTime").asText())
        assertEquals("2026-05-29T02:00:00", node.get("endDateTime").asText())
        assertFalse(node.get("createdAt").asText().endsWith("Z"), "не ожидалась зона Z")
    }
}
