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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogResponse;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.FilteredEntityLogRequest;

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 EntityLogResource {

    String ENTITY_LOG_PATH = ExternalApi.BASE_PATH + "/entityLog";

    String FILE_ID = "fileId";
    String FILE_ID_PATH_VARIABLE = "/{" + FILE_ID + "}";

    String DOSSIER_ID = "dossierId";
    String DOSSIER_ID_PATH_VARIABLE = "/{" + DOSSIER_ID + "}";
    String ANALYSIS_NUMBER = "analysisNumber";
    String ANALYSIS_NUMBER_PATH_VARIABLE = "/{" + ANALYSIS_NUMBER + "}";

    String FALSE = "false";


    @GetMapping(value = ENTITY_LOG_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Gets the entity log for a fileId", description =
            "Gets the entity log for a given file. The flag includeUnprocessed will merge into the entity log all the unprocessed changes if it's set to true."
            + "Default value for the flag is false.")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The dossier / file / entity log is not found.")})
    EntityLogResponse getEntityLog(@PathVariable(DOSSIER_ID) String dossierId,
                                   @PathVariable(FILE_ID) String fileId,
                                   @RequestParam(value = "excludedTypes", required = false, defaultValue = "") List<String> excludedTypes,
                                   @RequestParam(value = "includeUnprocessed", required = false, defaultValue = FALSE) boolean includeUnprocessed);


    @GetMapping(value = ENTITY_LOG_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE + "/filtered", produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Gets the entity log for a fileId greater than the specified date", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The dossier / file / entity log is not found.")})
    EntityLogResponse getFilteredEntityLog(@PathVariable(DOSSIER_ID) String dossierId,
                                           @PathVariable(FILE_ID) String fileId,
                                           @RequestBody FilteredEntityLogRequest filteredEntityLogRequest);


    @GetMapping(value = ENTITY_LOG_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE + "/pages", produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Gets the entity log for a fileId with all entities found on the given page numbers", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The dossier / file / entity log is not found.")})
    EntityLogResponse getEntityLogWithEntriesOnPages(@PathVariable(DOSSIER_ID) String dossierId,
                                                     @PathVariable(FILE_ID) String fileId,
                                                     @RequestParam(value = "pageNumbers", defaultValue = "") List<Integer> pageNumbers);


    @GetMapping(value = ENTITY_LOG_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE + ANALYSIS_NUMBER_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Gets the entity log for a fileId with all entities being analysed in or after iteration with given number", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The dossier / file / entity log is not found.")})
    EntityLogResponse getEntityLogDeltaUpdate(@PathVariable(DOSSIER_ID) String dossierId,
                                              @PathVariable(FILE_ID) String fileId,
                                              @PathVariable(ANALYSIS_NUMBER) Integer analysisNumber,
                                              @RequestParam(value = "includeUnprocessed", required = false, defaultValue = FALSE) boolean includeUnprocessed);

}
