package com.iqser.red.service.persistence.management.v1.processor.service;

import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ExcludeFromAnalysisService {

    private final FileStatusService fileStatusService;


    public void toggleExclusion(String dossierId, String fileId, boolean excluded) {

        var status = fileStatusService.getStatus(fileId);

        if (WorkflowStatus.APPROVED.equals(status.getWorkflowStatus())) {
            throw new BadRequestException("File in workflow status " + status.getWorkflowStatus() + " cannot be excluded/included");
        }

        // toggle status
        fileStatusService.toggleExclusion(dossierId, fileId, excluded);
    }


    public void toggleAutomaticAnalysis(String dossierId, String fileId, boolean excludedFromAutomaticAnalysis) {

        fileStatusService.toggleAutomaticAnalysis(dossierId, fileId, excludedFromAutomaticAnalysis);
    }

}
