package space.nstart.pcp.tle_monitoring_service.service

import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Flux
import space.nstart.pcp.pcp_types_lib.dto.satellite.SatelliteSummaryDTO
import space.nstart.pcp.pcp_types_lib.dto.satellite.SatelliteInfoDTO


@Service
class ComplexMissionService
    (private val webClientBuilder: WebClient.Builder) {

    @Value("\${settings.satellite-catalog-service:\${settings.complex-mission-service:pcp-satellite-catalog-service}}")
    val satelliteCatalogServiceURI = "pcp-satellite-catalog-service"


    fun getSatellites(): Flux<SatelliteInfoDTO> =
        webClientBuilder.build()
            .get()
            .uri("$satelliteCatalogServiceURI/api/satellites")
            .retrieve()
            .bodyToFlux(SatelliteSummaryDTO::class.java)
            .map { satellite ->
                SatelliteInfoDTO(
                    noradId = satellite.id,
                    name = satellite.name,
                    red = satellite.visualization.red,
                    green = satellite.visualization.green,
                    blue = satellite.visualization.blue,
                    scanTLE = satellite.scanTle,
                    code = satellite.code,
                    typeCode = satellite.typeCode,
                    active = satellite.active
                )
            }
}
