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

import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttributes;
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.ProcessingStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;

import lombok.experimental.UtilityClass;

@UtilityClass
public class FileStatusMapper {

    public FileStatus toFileStatus(FileModel status) {

        return FileStatus.builder()
                .dossierId(status.getDossierId())
                .dossierArchived(status.isDossierArchived())
                .dossierStatusId(status.getDossierStatusId())
                .dossierTemplateId(status.getDossierTemplateId())
                .fileId(status.getId())
                .filename(status.getFilename())
                .processingStatus(ProcessingStatus.valueOf(status.getProcessingStatus().name()))
                .workflowStatus(WorkflowStatus.valueOf(status.getWorkflowStatus().name()))
                .numberOfPages(status.getNumberOfPages())
                .added(status.getAdded())
                .lastUpdated(status.getLastUpdated())
                .numberOfAnalyses(status.getNumberOfAnalyses())
                .assignee(status.getAssignee())
                .lastReviewer(status.getLastReviewer())
                .lastApprover(status.getLastApprover())
                .hasUpdates(status.isHasUpdates())
                .hasImages(status.isHasImages())
                .hasRequests(status.isHasSuggestions())
                .hasSuggestions(status.isHasSuggestions())
                .excludedFromAutomaticAnalysis(status.isExcludedFromAutomaticAnalysis())
                .hasHints(status.isHasHints())
                .hasRedactions(status.isHasRedactions())
                .ocrEndTime(status.getOcrEndTime())
                .ocrStartTime(status.getOcrStartTime())
                .numberOfOCRedPages(status.getNumberOfOCRedPages() != null ? status.getNumberOfOCRedPages() : 0)
                .numberOfPagesToOCR(status.getNumberOfPagesToOCR() != null ? status.getNumberOfPagesToOCR() : 0)
                .hasAnnotationComments(status.isHasAnnotationComments())
                .uploader(status.getUploader())
                .dictionaryVersion(status.getDictionaryVersion())
                .aiCreationVersion(status.getAiCreationVersion())
                .rulesVersion(status.getRulesVersion())
                .componentRulesVersion(status.getComponentRulesVersion())
                .dateFormatsVersion(status.getDateFormatsVersion())
                .legalBasisVersion(status.getLegalBasisVersion())
                .lastProcessed(status.getLastProcessed())
                .lastLayoutProcessed(status.getLastLayoutProcessed())
                .approvalDate(status.getApprovalDate())
                .lastUploaded(status.getLastUploaded())
                .analysisDuration(status.getAnalysisDuration())
                .fileAttributes(new FileAttributes(status.getFileAttributes()))
                .dossierDictionaryVersion(status.getDossierDictionaryVersion())
                .excluded(status.isExcluded())
                .excludedPages(status.getExcludedPages())
                .softDeletedTime(status.getDeleted())
                .hardDeletedTime(status.getHardDeletedTime())
                .analysisRequired(status.isAnalysisRequired())
                .lastFileAttributeChange(status.getLastFileAttributeChange())
                .redactionModificationDate(status.getRedactionModificationDate())
                .fileManipulationDate(status.getFileManipulationDate())
                .lastManualChangeDate(status.getLastManualChangeDate())
                .hasHighlights(status.isHasHighlights())
                .lastIndexed(status.getLastIndexed())
                .fileSize(status.getFileSize())
                .fileErrorInfo(status.getFileErrorInfo())
                .componentMappingVersions(status.getComponentMappingVersions())
                .lastDownload(status.getLastDownloadDate())
                .build();

    }

}
