package com.iqser.red.service.persistence.service.v1.api.shared.model;

import java.time.OffsetDateTime;
import java.util.Set;

import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileErrorInfo;
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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Schema(description = "Object containing information on a specific file.")
public class FileStatus {

    @Schema(description = "The ID of the dossier the file belongs to.")
    private String dossierId;

    @Schema(description = "The ID of the dossier template of the dossier the file belongs to.")
    private String dossierTemplateId;

    @Schema(description = "The ID of the dossier status of the dossier the file belongs to.")
    private String dossierStatusId;

    @Schema(description = "The ID of the file.")
    private String fileId;

    @Schema(description = "The file's name.")
    private String filename;

    @Schema(description = "Tells if the dossier of this file is archived or not.")
    private boolean dossierArchived;

    @Schema(description = "The processing status of a file")
    private ProcessingStatus processingStatus;

    @Schema(description = "The workflow status of a file")
    private WorkflowStatus workflowStatus;

    @Schema(description = "The number of pages of the file.")
    private int numberOfPages;

    @Schema(description = "Date and time when the file was added to the system.")
    private OffsetDateTime added;

    @Schema(description = "Date and time when the file was last updated.")
    private OffsetDateTime lastUpdated;

    @Schema(description = "The number of times the file has been analyzed.")
    private int numberOfAnalyses;

    @Schema(description = "The current assignee's (if any) user id.")
    private String assignee;

    @Schema(description = "The last reviewer's (if any) user id.")
    private String lastReviewer;

    @Schema(description = "The last approvers's (if any) user id.")
    private String lastApprover;

    @Schema(description = "Shows if any redactions were found during the analysis.")
    private boolean hasRedactions;

    @Schema(description = "Shows if any hints were found during the analysis.")
    private boolean hasHints;

    @Deprecated
    @Schema(description = "Shows if any requests were found during the analysis.")
    private boolean hasRequests;

    @Schema(description = "Shows if there is any change between the previous and current analysis.")
    private boolean hasUpdates;

    @Schema(description = "Shows if any images were found during the analysis.")
    private boolean hasImages;
    @Schema(description = "Shows if this file has been OCRed by us. Start time of OCR Process")
    private OffsetDateTime ocrStartTime;
    @Schema(description = "Number of pages to be OCRed by us")
    private int numberOfPagesToOCR;
    @Schema(description = "Number of pages already OCRed by us")
    private int numberOfOCRedPages;
    @Schema(description = "Shows if this file has been OCRed by us. End time of OCR Process")
    private OffsetDateTime ocrEndTime;
    @Schema(description = "Shows if this file has comments on annotations.")
    private boolean hasAnnotationComments;
    @Schema(description = "The ID of the user who uploaded the file.")
    private String uploader;
    @Schema(description = "Shows which dictionary versions was used during the analysis.")
    private long dictionaryVersion;
    @Schema(description = "Shows which entity rules versions was used during the analysis.")
    private long rulesVersion;
    @Schema(description = "Shows which component rules versions was used during the analysis.")
    private long componentRulesVersion;
    @Schema(description = "Shows which legal basis versions was used during the analysis.")
    private long legalBasisVersion;
    @Schema(description = "Shows if the file was excluded from analysis.")
    private boolean excluded;
    @Schema(description = "Shows the last date of a successful analysis.")
    private OffsetDateTime lastProcessed;
    @Schema(description = "Shows the last date of a layout parsing.")
    private OffsetDateTime lastLayoutProcessed;
    @Schema(description = "Shows the date of approval, if approved.")
    private OffsetDateTime approvalDate;
    @Schema(description = "Shows last date the document was uploaded.")
    private OffsetDateTime lastUploaded;
    @Schema(description = "Shows how long the last analysis took")
    private long analysisDuration;
    @Schema(description = "Additional file attributes that can be set or imported")
    private FileAttributes fileAttributes;
    @Schema(description = "Shows which dossier dictionary versions was used during the analysis.")
    private long dossierDictionaryVersion;
    @Schema(description = "Shows if the file requires reanalysis.")
    private boolean analysisRequired;
    @Schema(description = "Set of excluded pages for this file.")
    private Set<Integer> excludedPages;
    @Schema(description = "Shows if the file is soft deleted.")
    private OffsetDateTime softDeletedTime;
    @Schema(description = "Date and time when the files attributes was last updated.")
    private OffsetDateTime lastFileAttributeChange;
    @Schema(description = "Shows if there are any Suggestions in this file.")
    private boolean hasSuggestions;
    @Schema(description = "Shows if the file is excluded from automatic analysis.")
    private boolean excludedFromAutomaticAnalysis;
    @Schema(description = "Shows the last redaction modification date of this file.")
    private OffsetDateTime redactionModificationDate;
    @Schema(description = "Shows the date of the last manipulation of this file.")
    private OffsetDateTime fileManipulationDate;
    @Schema(description = "Shows the date of the last manual change of an annotation of this file.")
    private OffsetDateTime lastManualChangeDate;
    @Schema(description = "Shows if there are highlights to remove or convert for this file.")
    private boolean hasHighlights;
    @Schema(description = "Size of the optimized, internally stored file.")
    private Long fileSize;
    @Schema(description = "Analysis Version.")
    private int analysisVersion;
    @Schema(description = "Last time the file was indexed in ES.")
    private OffsetDateTime lastIndexed;
    @Schema(description = "The error information for the error state of the file")
    private FileErrorInfo fileErrorInfo;


    @Schema(description = "Shows if this file has been OCRed by us. Last Time of OCR.")
    public OffsetDateTime getLastOCRTime() {

        return ocrEndTime != null ? ocrEndTime : ocrStartTime;
    }


    public String getId() {

        return fileId;
    }

}
