package space.nstart.pcp.pcp_satellites_service.service

import org.springframework.stereotype.Service
import space.nstart.pcp.pcp_satellites_service.model.mode.SurveyMode
import space.nstart.pcp.pcp_types_lib.dto.satellite.mission.MissionStatisticsDTO
import space.nstart.pcp.pcp_types_lib.dto.satellite.mission.SatelliteModeResponseDTO
import space.nstart.pcp.pcp_types_lib.dto.satellite.mission.SatelliteModeSnapshotResponseDTO
import space.nstart.pcp.pcp_types_lib.dto.satellite.modes.SurveyModeInfoDTO
import java.time.LocalDateTime

@Service
class ComplexPlanQueryService(
    private val satelliteModeQueryService: SatelliteModeQueryService
) {

    fun findMissionModes(satelliteId: Long): List<SurveyModeInfoDTO> =
        satelliteModeQueryService.findMissionModes(satelliteId)

    fun missionStatistics(satelliteId: Long): MissionStatisticsDTO =
        satelliteModeQueryService.missionStatistics(satelliteId)

    fun buildPaintGeometry(satelliteId: Long): String =
        satelliteModeQueryService.buildPaintGeometry(satelliteId)

    fun buildCellPaintGeometry(cellNum: Long): String =
        satelliteModeQueryService.buildCellPaintGeometry(cellNum)

    fun findModesByInterval(
        satelliteIds: Collection<Long>,
        intervalStart: LocalDateTime,
        intervalEnd: LocalDateTime,
        runId: Long? = null
    ): List<SatelliteModeResponseDTO> =
        satelliteModeQueryService.findModesByInterval(satelliteIds, intervalStart, intervalEnd, runId)

    fun findSnapshot(snapshotId: Long): SatelliteModeSnapshotResponseDTO =
        satelliteModeQueryService.findSnapshot(snapshotId)

    fun findSnapshots(
        satelliteId: Long?,
        intervalStart: LocalDateTime?,
        intervalEnd: LocalDateTime?,
        activeOnly: Boolean
    ): List<SatelliteModeSnapshotResponseDTO> =
        satelliteModeQueryService.findSnapshots(
            satelliteId = satelliteId,
            intervalStart = intervalStart,
            intervalEnd = intervalEnd,
            activeOnly = activeOnly
        )

    fun findActiveSnapshot(
        satelliteId: Long,
        intervalStart: LocalDateTime? = null,
        intervalEnd: LocalDateTime? = null
    ): SatelliteModeSnapshotResponseDTO? =
        satelliteModeQueryService.findActiveSnapshot(satelliteId, intervalStart, intervalEnd)

    fun findModesBySnapshot(
        snapshotId: Long,
        intervalStart: LocalDateTime? = null,
        intervalEnd: LocalDateTime? = null
    ): List<SatelliteModeResponseDTO> =
        satelliteModeQueryService.findModesBySnapshot(snapshotId, intervalStart, intervalEnd)

    fun loadWorkingModes(
        satelliteIds: Collection<Long>,
        intervalStart: LocalDateTime,
        intervalEnd: LocalDateTime
    ): Map<Long, MutableList<SurveyMode>> =
        satelliteModeQueryService.loadWorkingModes(satelliteIds, intervalStart, intervalEnd)

    fun loadConstraintModes(
        satelliteIds: Collection<Long>,
        intervalStart: LocalDateTime,
        intervalEnd: LocalDateTime
    ): Map<Long, MutableList<SurveyMode>> =
        satelliteModeQueryService.loadConstraintModes(satelliteIds, intervalStart, intervalEnd)

    fun loadDayConstraintModes(
        satelliteIds: Collection<Long>,
        intervalStart: LocalDateTime,
        intervalEnd: LocalDateTime
    ): Map<Long, MutableList<SurveyMode>> =
        satelliteModeQueryService.loadDayConstraintModes(satelliteIds, intervalStart, intervalEnd)

    fun loadRevolutionConstraintModes(
        satelliteIds: Collection<Long>,
        intervalStart: LocalDateTime,
        intervalEnd: LocalDateTime
    ): Map<Long, MutableList<SurveyMode>> =
        satelliteModeQueryService.loadRevolutionConstraintModes(satelliteIds, intervalStart, intervalEnd)
}
