package space.nstart.pcp.pcp_mission_planing_service.controller

import org.junit.jupiter.api.Test
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import space.nstart.pcp.pcp_types_lib.dto.routes.SurveyModeStatus
import space.nstart.pcp.pcp_mission_planing_service.service.MissionPlaningService
import space.nstart.pcp.pcp_types_lib.dto.satellite.mission.MissionSurveyCalculationResponseDTO
import java.time.LocalDateTime
import java.util.UUID
import kotlin.test.assertEquals

class MissionControllerTest {

    private val missionPlaningService = mock(MissionPlaningService::class.java)
    private val controller = MissionController(missionPlaningService)

    @Test
    fun `calculate surveys endpoint accepts satellite and interval overrides`() {
        val missionId = UUID.randomUUID()
        val startedAt = LocalDateTime.of(2026, 4, 2, 10, 0)
        val responseBody = MissionSurveyCalculationResponseDTO(
            missionId = missionId,
            completed = true,
            startedAt = startedAt,
            finishedAt = startedAt.plusSeconds(2),
            durationMs = 2_000,
            comPlanSnapshotId = 99L,
            surveyModesCount = 3,
            manualModesCount = 1,
            complanModesCount = 1,
            slotsModesCount = 1,
            mixedModesCount = 0,
            bookedSlotIdsCount = 4
        )
        doReturn(responseBody).`when`(missionPlaningService).loadSlots(missionId, comPlanSnapshotId = 99L)

        val response = controller.calculateSurveys(
            id = missionId,
            comPlanSnapshotId = 99L
        )

        assertEquals(responseBody, response)
        verify(missionPlaningService).loadSlots(missionId, comPlanSnapshotId = 99L)
    }

    @Test
    fun `update survey mode status endpoint delegates to service`() {
        val response = controller.updateSurveyModeStatus(
            id = 15L,
            body = SurveyModeStatusUpdateRequest(status = SurveyModeStatus.PROCESSED)
        )

        assertEquals(org.springframework.http.HttpStatus.NO_CONTENT, response.statusCode)
        verify(missionPlaningService).updateSurveyModeStatus(15L, SurveyModeStatus.PROCESSED)
    }
}
