package com.iqser.red.service.persistence.v1.internal.api.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.iqser.red.service.persistence.management.v1.processor.service.UploadManagementService;
import com.iqser.red.service.persistence.service.v1.api.internal.resources.UploadResource;
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileUploadResult;

import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequiredArgsConstructor
@Slf4j
@SuppressWarnings("PMD")
public class UploadInternalController implements UploadResource {

    private final UploadManagementService uploadManagementService;


    @Override
    public FileUploadResult upload(@RequestPart(name = "file") MultipartFile file,
                                   @PathVariable(DOSSIER_ID) String dossierId,
                                   @RequestParam(value = "keepManualRedactions", required = false, defaultValue = "false") boolean keepManualRedactions,
                                   @Parameter(name = DISABLE_AUTOMATIC_ANALYSIS_PARAM, description = "Disables automatic redaction for the uploaded file, imports only imported redactions") @RequestParam(value = DISABLE_AUTOMATIC_ANALYSIS_PARAM, required = false, defaultValue = "false") boolean disableAutomaticAnalysis) {

        return uploadManagementService.upload(file, dossierId, keepManualRedactions, disableAutomaticAnalysis);
    }

}
