package com.iqser.red.service.persistence.service.v1.api.external.resource;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.iqser.red.service.persistence.service.v1.api.shared.model.DossierStatusRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.DossierStatusInfo;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;

@ResponseStatus(value = HttpStatus.OK)
public interface DossierStatusResource {

    String DOSSIER_STATUS_PATH = ExternalApi.BASE_PATH + "/dossier-status";
    String DOSSIER_TEMPLATE_PATH = "/dossier-template";
    String DOSSIER_TEMPLATE_ID = "dossierTemplateId";
    String DOSSIER_TEMPLATE_ID_PATH_VARIABLE = "/{" + DOSSIER_TEMPLATE_ID + "}";

    String DOSSIER_STATUS_ID = "dossierStatusId";
    String DOSSIER_STATUS_ID_PATH_VARIABLE = "/{" + DOSSIER_STATUS_ID + "}";

    String DOSSIER_STATUS_REPLACE_ID = "replaceDossierStatusId";


    @Operation(summary = "Creates or updates dossier status", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Dossier status updated"), @ApiResponse(responseCode = "404", description = "The dossier status not found.")})

    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @PostMapping(value = DOSSIER_STATUS_PATH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    DossierStatusInfo createOrUpdateDossierStatus(@RequestBody DossierStatusRequest dossierStatusRequest);


    @Operation(summary = "Retrieves all dossier status for a dossier template", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Dossier status list retrieved")})
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @GetMapping(value = DOSSIER_STATUS_PATH + DOSSIER_TEMPLATE_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    List<DossierStatusInfo> getAllDossierStatusForTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId);


    @Operation(summary = "Retrieves all dossier status for a dossier template", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Dossier status list retrieved")})
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @PostMapping(value = DOSSIER_STATUS_PATH + DOSSIER_TEMPLATE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    List<DossierStatusInfo> getAllDossierStatuses(@RequestBody List<String> dossierTemplateIds);


    @Operation(summary = "Retrieves dossier status", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Dossier status retrieved")})
    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @GetMapping(value = DOSSIER_STATUS_PATH + DOSSIER_STATUS_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    DossierStatusInfo getDossierStatus(@PathVariable(DOSSIER_STATUS_ID) String dossierStatusId);


    @Operation(summary = "Delete dossier status and update dossiers with a new status", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Successfully deleted the dossier status."), @ApiResponse(responseCode = "404", description = "Not found")})
    @ResponseBody
    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @DeleteMapping(value = DOSSIER_STATUS_PATH + DOSSIER_STATUS_ID_PATH_VARIABLE)
    void deleteDossierStatus(@PathVariable(DOSSIER_STATUS_ID) String dossierStatusId,
                             @RequestParam(value = DOSSIER_STATUS_REPLACE_ID, required = false) String replaceDossierStatusId);

}
