package com.iqser.red.persistence.service.v1.external.api.impl.controller;

import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_REDACTION_LOG;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
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.RestController;

import com.iqser.red.service.persistence.management.v1.processor.service.ComponentLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.service.v1.api.external.resource.AnalysisLogResource;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.FilteredEntityLogRequest;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class AnalysisLogController implements AnalysisLogResource {

    private final EntityLogService entityLogService;
    private final ComponentLogService componentLogService;


    @PreAuthorize("hasAuthority('" + READ_REDACTION_LOG + "')")
    public EntityLog getEntityLog(@PathVariable(DOSSIER_ID) String dossierId,
                                  @PathVariable(FILE_ID) String fileId,
                                  @RequestParam(value = "excludedType", required = false) List<String> excludedTypes,
                                  @RequestParam(value = "withManualRedactions", required = false, defaultValue = "true") boolean withManualRedactions,
                                  @RequestParam(value = "includeFalsePositives", required = false, defaultValue = "false") boolean includeFalsePositives) {

        return entityLogService.getEntityLog(dossierId, fileId, excludedTypes);
    }


    @PreAuthorize("hasAuthority('" + READ_REDACTION_LOG + "')")
    public EntityLog getFilteredEntityLog(@PathVariable(DOSSIER_ID) String dossierId,
                                          @PathVariable(FILE_ID) String fileId,
                                          @RequestBody FilteredEntityLogRequest filteredEntityLogRequest) {

        return entityLogService.getFilteredEntityLog(dossierId, fileId, filteredEntityLogRequest);
    }


    @Override
    public ComponentLog getComponentLog(String dossierId, String fileId) {

        return componentLogService.getComponentLog(dossierId, fileId);
    }

}
