package dp.kotul.templategroupsbackend.controller

import dp.kotul.starter.global.DefaultApiResponses
import dp.kotul.templategroupsbackend.facade.TemplateGroupFacade
import dp.kotul.templategroupsbackend.model.entity.TemplateGroup
import dp.kotul.templategroupsbackend.model.request.TemplateGroupRequest
import dp.kotul.templategroupsbackend.model.response.TemplateGroupDetailResponse
import dp.kotul.templategroupsbackend.model.response.TemplateGroupResponse
import dp.kotul.templategroupsbackend.model.solrsearch.SolrSearchRequest
import dp.kotul.templategroupsbackend.model.solrsearch.tamplategroup.TemplateGroupSolrResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.OK
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
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.RequestParam
import org.springframework.web.bind.annotation.RestController

@Api(tags = ["Template groups"], description = "Provides API for template groups operations")
@DefaultApiResponses
@RestController
@RequestMapping("/template-groups")
class TemplateGroupController(val templateGroupFacade: TemplateGroupFacade) {

    @ApiOperation(value = "Get template groups", notes = "Returns template groups defined for current user by company id")
    @GetMapping
    fun getTemplateGroups(): List<TemplateGroup> {
        return templateGroupFacade.getTemplateGroups()
    }

    @ApiOperation(value = "Get template group", notes = "Returns template group defined by template group id")
    @GetMapping("/{templateGroupId}")
    fun getTemplateGroup(
        @ApiParam(value = "Template Group ID", required = true) @PathVariable templateGroupId: Int,
        @ApiParam(value = "Language ID", required = false) @RequestParam laeId: Int?
    ): TemplateGroupResponse? {
        return templateGroupFacade.getTemplateGroup(templateGroupId, laeId)
    }

    @ApiOperation(value = "Create template group", notes = "Create template group defined by template group request")
    @PostMapping
    fun createTemplateGroup(
        @ApiParam(value = "Template Group Request", required = true) @RequestBody templateGroupRequest: TemplateGroupRequest
    ): TemplateGroup {
        return templateGroupFacade.createTemplateGroup(templateGroupRequest)
    }

    @ApiOperation(value = "Update template group", notes = "Update template group defined by template group request")
    @PutMapping
    fun updateTemplateGroup(
        @ApiParam(value = "Template Group Request", required = true) @RequestBody templateGroupRequest: TemplateGroupRequest
    ): TemplateGroup? {
        return templateGroupFacade.updateTemplateGroup(templateGroupRequest)
    }
}
