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

import java.util.Set;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;

import com.iqser.red.service.persistence.service.v1.api.shared.model.FileUploadResult;

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

public interface UploadResource {

    String DOSSIER_ID = "dossierId";
    String FILE_ID = "fileId";
    String UPLOAD_PATH = ExternalApi.BASE_PATH + "/upload";
    String IMPORT_REDACTIONS_PATH = ExternalApi.BASE_PATH + "/import-redactions";
    String DOSSIER_ID_PATH_VARIABLE = "/{" + DOSSIER_ID + "}";
    String FILE_ID_PATH_VARIABLE = "/{" + FILE_ID + "}";


    @ResponseBody
    @ResponseStatus(value = HttpStatus.CREATED)
    @PostMapping(value = UPLOAD_PATH + DOSSIER_ID_PATH_VARIABLE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Receives an uploaded file and returns its fileId.", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "File upload succeeded. Return the fileId of the " + "uploaded file.")})
    FileUploadResult upload(@RequestPart(name = "file") MultipartFile file,
                            @PathVariable(DOSSIER_ID) String dossierId,
                            @RequestParam(value = "keepManualRedactions", required = false, defaultValue = "false") boolean keepManualRedactions);


    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @PostMapping(value = IMPORT_REDACTIONS_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "Imports redactions from a redacted file to a existing file", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Ok")})
    void importRedactions(@RequestPart(name = "file") MultipartFile file,
                          @PathVariable(DOSSIER_ID) String dossierId,
                          @PathVariable(FILE_ID) String fileId,
                          @RequestParam(value = "pageInclusionRequest", required = false) Set<Integer> pageInclusionRequest);

}
