package space.nstart.pcp.slots_service.controller

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
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.pcp_types_lib.dto.ballistics.StationDTO
import space.nstart.pcp.slots_service.service.SlotService
import java.time.LocalDateTime


@RestController
@RequestMapping("/api/satellite")
class SatelliteController {

    @Autowired
    private lateinit var slotService: SlotService

    @PostMapping("/rva/{id}/{duration}")
    fun rva(@PathVariable id : Long, @PathVariable duration: Long, @RequestBody station : StationDTO)
    = slotService.rva(id, duration, station)


    @PostMapping("/rva-common/{id}/{duration}")
    fun rvaCommon(@PathVariable id : Long, @PathVariable duration: Long, @RequestBody station : List<StationDTO>)
            = slotService.rvaCommon(id, duration, station)

    @PostMapping("/rva-merge/{id}/{duration}")
    fun rvaMerge(@PathVariable id : Long, @PathVariable duration: Long, @RequestBody station : List<StationDTO>)
            = slotService.rvaMerge(id, duration, station)

    @PostMapping("/rva-merge-on-rev/{id}/{duration}")
    fun rvaMergeOnRev(@PathVariable id : Long, @PathVariable duration: Long, @RequestBody station : List<StationDTO>)
            = slotService.rvaMergeOnRev(id, duration, station)


    @PostMapping("/{id}/send-ic")
    fun publishInitialConditions(@PathVariable id: Long, @RequestParam time : LocalDateTime): ResponseEntity<Void> {
        slotService.publishInitialConditions(id, time, true)
        return ResponseEntity.accepted().build()
    }

}
