package space.nstart.pcp.slots_service.controller

import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import space.nstart.pcp.slots_service.service.TleAnalysisService

@RestController
@RequestMapping("/api/tle-analysis")
class TleAnalysisController(
    private val tleAnalysisService: TleAnalysisService
) {
    private val logger = LoggerFactory.getLogger(this::class.java)

    @GetMapping("/satellites")
    fun satellites() =
        tleAnalysisService.satellites().also { satellites ->
            logger.info("TLE analysis satellites request completed: satellites={}", satellites.size)
        }

    @GetMapping("/satellites/{satelliteId}")
    fun analyzeSatellite(
        @PathVariable satelliteId: Long,
        @RequestParam(defaultValue = "5") tleCount: Int
    ) = tleAnalysisService.analyzeSatellite(satelliteId, tleCount).also { response ->
        logger.info(
            "TLE analysis report request completed: satelliteId={}, requestedTleCount={}, rows={}",
            satelliteId,
            tleCount,
            response.rows.size
        )
    }

    @GetMapping("/satellites/{satelliteId}/analysis")
    fun analyzeSatelliteDetails(
        @PathVariable satelliteId: Long,
        @RequestParam(defaultValue = "5") tleCount: Int
    ) = analyzeSatellite(satelliteId, tleCount)
}
