package space.nstart.pcp.slots_service.controller

import org.springframework.stereotype.Controller
import org.springframework.http.HttpStatus
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.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import space.nstart.pcp.slots_service.service.ComplexMissionService

@Controller
class ComplexPlanPageController {

    @GetMapping("/com-plan")
    fun complexPlanPage(): String = "complex-plan"
}

@RestController
@RequestMapping("/api/com-plan/runs")
class ComplexPlanRunsRestController(
    private val complexMissionService: ComplexMissionService
) {

    @GetMapping
    @ResponseBody
    fun runs() = complexMissionService.complexPlanRuns()

    @GetMapping("/{id}")
    @ResponseBody
    fun run(@PathVariable id: Long) = complexMissionService.complexPlanRun(id)

    @GetMapping("/{id}/modes")
    @ResponseBody
    fun runModes(@PathVariable id: Long) = complexMissionService.complexPlanRunModes(id)

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    fun deleteRun(@PathVariable id: Long) {
        complexMissionService.deleteComplexPlanRun(id)
    }
}
