package dp.kotul.templategroupsbackend.client

import dp.kotul.solrapimodel.SolrApiSearchParameters
import dp.kotul.starter.config.FeignConfiguration
import dp.kotul.starter.filter.AUTHORIZATION_HEADER
import dp.kotul.starter.filter.RequestCorrelation
import dp.kotul.templategroupsbackend.model.request.UpdateTemplateGroupsSolrRequest
import dp.kotul.templategroupsbackend.model.solrsearch.tamplategroup.TemplateGroupSolrResponse
import dp.kotul.templategroupsbackend.model.solrsearch.template.TemplateSolrResponse
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.http.MediaType
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.RequestHeader
import org.springframework.web.bind.annotation.RequestParam

@FeignClient(name = "SolrApiClient", url = "\${solr-api.url}/v1", configuration = [FeignConfiguration::class])
interface SolrApiClient {

    @PostMapping(value = ["/documents"], consumes = [MediaType.APPLICATION_JSON_VALUE])
    fun getSolrTemplatesResponse(
            @RequestHeader(AUTHORIZATION_HEADER) accessToken: String,
            @RequestHeader(RequestCorrelation.CORRELATION_ID_HEADER) correlationId: String,
            @RequestParam laeId: Int,
            @RequestBody searchParameters: SolrApiSearchParameters): TemplateSolrResponse?

    @PostMapping(value = ["/documents"], consumes = [MediaType.APPLICATION_JSON_VALUE])
    fun getSolrTemplateGroupsResponse(
            @RequestHeader(AUTHORIZATION_HEADER) accessToken: String,
            @RequestHeader(RequestCorrelation.CORRELATION_ID_HEADER) correlationId: String,
            @RequestParam laeId: Int,
            @RequestBody searchParameters: SolrApiSearchParameters): TemplateGroupSolrResponse?

    @PutMapping(value = ["/template-groups"], consumes = [MediaType.APPLICATION_JSON_VALUE])
    fun updateSolrTemplateGroups(
            @RequestHeader(AUTHORIZATION_HEADER) accessToken: String,
            @RequestHeader(RequestCorrelation.CORRELATION_ID_HEADER) correlationId: String,
            @RequestBody updateTemplateGroupsSolrRequest: UpdateTemplateGroupsSolrRequest)
}
