package space.nstart.pcp.slots_service.controller

import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import space.nstart.pcp.pcp_types_lib.dto.ballistics.InitialConditionsDTO
import space.nstart.pcp.pcp_types_lib.dto.ballistics.SatelliteICDTO
import space.nstart.pcp.slots_service.service.SatelliteIcService

@RestController
@RequestMapping("/api/satellite-ic")
class SatelliteIcController(
    private val satelliteIcService: SatelliteIcService
) {

    @GetMapping
    fun all() = satelliteIcService.all()

    @GetMapping("/{satellite_id}")
    fun bySatelliteId(@PathVariable("satellite_id") satelliteId: Long) =
        satelliteIcService.bySatelliteId(satelliteId)

    @PostMapping
    fun create(@RequestBody request: SatelliteICDTO) =
        satelliteIcService.create(request)

    @PutMapping("/{satellite_id}")
    fun update(
        @PathVariable("satellite_id") satelliteId: Long,
        @RequestBody request: InitialConditionsDTO
    ) = satelliteIcService.update(satelliteId, request)

    @DeleteMapping("/{satellite_id}")
    fun delete(@PathVariable("satellite_id") satelliteId: Long): ResponseEntity<Void> {
        satelliteIcService.delete(satelliteId)
        return ResponseEntity.noContent().build()
    }
}
