package dp.kotul.solrapiapplication.v1.controller

import com.fasterxml.jackson.databind.JsonNode
import dp.kotul.solrapiapplication.facade.SolrDocumentFacade
import dp.kotul.solrapimodel.SolrApiSearchParameters
import dp.kotul.starter.global.DefaultApiResponses
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
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 = ["Solr Document"], description = "Provides API for solr documents operations")
@DefaultApiResponses
@RestController
@RequestMapping(value = ["/v1/documents"])
class SolrDocumentController(val solrDocumentFacade: SolrDocumentFacade) {

    @ApiOperation(value = "Get documents", notes = "Get documents specified by solr search parameters")
    @PostMapping(consumes = ["application/json"], produces = ["application/json"])
    fun getDocuments(
            @ApiParam("Language ID", required = true) @RequestParam laeId: Int,
            @ApiParam("Search parameters defined in Solr API", required = true) @RequestBody searchParameters: SolrApiSearchParameters
    ): ResponseEntity<JsonNode?> {
        return solrDocumentFacade.getDocuments(laeId, searchParameters)
    }
}
