package dp.kotul.templategroupsbackend.controller

import dp.kotul.starter.global.DefaultApiResponses
import dp.kotul.templategroupsbackend.facade.TemplateGroupVariableFacade
import dp.kotul.templategroupsbackend.model.entity.TemplateGroupVariable
import dp.kotul.templategroupsbackend.model.response.TemplateGroupVariableRequestResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
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.RequestParam
import org.springframework.web.bind.annotation.RestController

@Api(tags = ["Template group variables"], description = "Provides API for template group variables operations")
@DefaultApiResponses
@RestController
@RequestMapping("/template-groups", produces = [MediaType.APPLICATION_JSON_VALUE])
class TemplateGroupVariableController(val templateGroupVariableFacade: TemplateGroupVariableFacade) {

    @ApiOperation(value = "Get template group variables", notes = "Returns template group variables defined for template group defined by template group id")
    @GetMapping("/{templateGroupId}/variables")
    fun getTemplateGroupVariables(
            @ApiParam(value = "Template Group ID", required = true) @PathVariable templateGroupId: Int,
            @ApiParam(value = "Language ID", required = false) @RequestParam laeId: Int?
    ): List<TemplateGroupVariableRequestResponse> {
        return templateGroupVariableFacade.getTemplateGroupVariables(templateGroupId, laeId)
    }

    @ApiOperation(value = "Update template group variables", notes = "Update template group variables defined for template group defined by template group id and template group variables request")
    @PutMapping("/{templateGroupId}/variables")
    fun updateTemplateGroupVariables(
            @ApiParam(value = "Template Group ID", required = true) @PathVariable templateGroupId: Int,
            @ApiParam(value = "Template Group Variables Request", required = true) @RequestBody templateGroupVariablesRequest: List<TemplateGroupVariableRequestResponse>
    ): List<TemplateGroupVariable> {
        return templateGroupVariableFacade.updateTemplateGroupVariables(templateGroupId, templateGroupVariablesRequest)
    }
}
