package org.nstart.dep265.requestservice.controller

import jakarta.validation.Valid
import org.nstart.dep265.requestservice.dto.GridRebuildResponseDto
import org.nstart.dep265.requestservice.dto.GridSettingsResponseDto
import org.nstart.dep265.requestservice.dto.UpdateGridSettingsRequestDto
import org.nstart.dep265.requestservice.service.GridRebuildService
import org.nstart.dep265.requestservice.service.GridSettingsService
import org.springframework.web.bind.annotation.GetMapping
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

@RestController
@RequestMapping("/v1/grid")
class GridManagementController(
    private val gridSettingsService: GridSettingsService,
    private val gridRebuildService: GridRebuildService,
) {
    @GetMapping("/settings")
    fun getGridSettings(): GridSettingsResponseDto {
        return gridSettingsService.getSettings()
    }

    @PutMapping("/settings")
    fun updateGridSettings(
        @Valid @RequestBody request: UpdateGridSettingsRequestDto,
    ): GridSettingsResponseDto {
        return gridSettingsService.updateSettings(request)
    }

    @PostMapping("/rebuild")
    fun rebuildGrid(): GridRebuildResponseDto {
        return gridRebuildService.rebuildGrid()
    }
}
