package space.nstart.pcp.pcp_satellite_catalog_service.controller

import jakarta.validation.Valid
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_satellite_catalog_service.service.SatelliteCatalogService
import space.nstart.pcp.pcp_types_lib.dto.satellite.SatelliteGroupCreateDTO
import space.nstart.pcp.pcp_types_lib.dto.satellite.SatelliteGroupUpdateDTO

@RestController
@RequestMapping("/api/satellite-groups")
class SatelliteGroupController(
    private val satelliteCatalogService: SatelliteCatalogService
) {

    @GetMapping
    fun all() = satelliteCatalogService.allGroups()

    @GetMapping("/{group_id}")
    fun byId(@PathVariable("group_id") groupId: Long) =
        satelliteCatalogService.groupById(groupId)

    @PostMapping
    fun create(@Valid @RequestBody request: SatelliteGroupCreateDTO) =
        satelliteCatalogService.createGroup(request)

    @PutMapping("/{group_id}")
    fun update(
        @PathVariable("group_id") groupId: Long,
        @Valid @RequestBody request: SatelliteGroupUpdateDTO
    ) = satelliteCatalogService.updateGroup(groupId, request)

    @DeleteMapping("/{group_id}")
    fun delete(@PathVariable("group_id") groupId: Long): ResponseEntity<Void> {
        satelliteCatalogService.deleteGroup(groupId)
        return ResponseEntity.noContent().build()
    }
}
