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.http.ResponseEntity;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.PlaceholdersResponse;
import com.iqser.red.service.persistence.service.v1.api.shared.model.ReportTemplateUpdateRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.ReportTemplate;

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

    String REPORT_TEMPLATE_UPLOAD_PATH = ExternalApi.BASE_PATH + "/templateUpload";
    String REPORT_TEMPLATES_PATH = ExternalApi.BASE_PATH + "/templates";
    String DOSSIER_TEMPLATE_ID = "dossierTemplateId";
    String DOSSIER_TEMPLATE_ID_PATH_VARIABLE = "/{" + DOSSIER_TEMPLATE_ID + "}";
    String TEMPLATE_ID = "templateId";
    String TEMPLATE_ID_PATH_VARIABLE = "/{" + TEMPLATE_ID + "}";
    String MULTI_FILE_REPORT = "multiFileReport";
    String ACTIVE_BY_DEFAULT = "activeByDefault";
    String PLACEHOLDERS_PATH = ExternalApi.BASE_PATH + "/placeholders";


    @PostMapping(value = REPORT_TEMPLATES_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Returns templates which contains given placeholder", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Report templates return succeeded.")})
    List<ReportTemplate> getReportTemplatesByPlaceholder(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @RequestBody JSONPrimitive<String> placeholder);


    @ResponseBody
    @ResponseStatus(value = HttpStatus.CREATED)
    @PostMapping(value = REPORT_TEMPLATE_UPLOAD_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Upload template file for redaction-report", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Report template upload succeeded.")})
    ReportTemplate uploadTemplate(@RequestPart(name = "file") MultipartFile file,
                                  @PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId,
                                  @RequestParam(value = MULTI_FILE_REPORT, required = false, defaultValue = "false") boolean multiFileReport,
                                  @RequestParam(value = ACTIVE_BY_DEFAULT, required = false, defaultValue = "false") boolean activeByDefault);


    @GetMapping(value = REPORT_TEMPLATE_UPLOAD_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Returns available templates for redaction-report", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Report template return succeeded.")})
    List<ReportTemplate> getAvailableReportTemplates(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId);


    @GetMapping(value = REPORT_TEMPLATE_UPLOAD_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Download template file for redaction-report", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Report template download succeeded.")})
    ResponseEntity<?> downloadReportTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @PathVariable(TEMPLATE_ID) String templateId);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @DeleteMapping(value = REPORT_TEMPLATE_UPLOAD_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + TEMPLATE_ID_PATH_VARIABLE)
    @Operation(summary = "Delete template file for redaction-report", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Report template deletion succeeded.")})
    void deleteTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @PathVariable(TEMPLATE_ID) String templateId);


    @GetMapping(value = PLACEHOLDERS_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Returns list of available placeholders", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Placeholders return succeeded.")})
    PlaceholdersResponse getAvailablePlaceholders(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @PutMapping(value = REPORT_TEMPLATE_UPLOAD_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + TEMPLATE_ID_PATH_VARIABLE)
    @Operation(summary = "Update template file for redaction-report", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Report template update succeeded.")})
    void updateTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId,
                        @PathVariable(TEMPLATE_ID) String templateId,
                        @RequestBody ReportTemplateUpdateRequest updateRequest);

}
