package tech.easyflow.ai.documentimport;

import com.easyagents.rag.core.RagChunk;
import com.easyagents.rag.ingestion.model.AnalysisResult;
import com.easyagents.rag.ingestion.model.StrategyConfig;
import tech.easyflow.ai.entity.Document;
import tech.easyflow.ai.entity.DocumentChunk;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public final class DocumentImportDtos {

    private DocumentImportDtos() {
    }

    public static class FileItem implements Serializable {
        private String filePath;
        private String fileName;

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
    }

    public static class AnalyzeRequest implements Serializable {
        private BigInteger knowledgeId;
        private List<FileItem> files = new ArrayList<FileItem>();

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public List<FileItem> getFiles() {
            return files;
        }

        public void setFiles(List<FileItem> files) {
            this.files = files;
        }
    }

    public static class PreviewFileRequest implements Serializable {
        private String filePath;
        private String fileName;
        private StrategyConfig strategyConfig = StrategyConfig.defaults();

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public StrategyConfig getStrategyConfig() {
            return strategyConfig;
        }

        public void setStrategyConfig(StrategyConfig strategyConfig) {
            this.strategyConfig = strategyConfig;
        }
    }

    public static class PreviewRequest implements Serializable {
        private BigInteger knowledgeId;
        private BigInteger documentId;
        private List<PreviewFileRequest> files = new ArrayList<PreviewFileRequest>();

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public List<PreviewFileRequest> getFiles() {
            return files;
        }

        public void setFiles(List<PreviewFileRequest> files) {
            this.files = files;
        }
    }

    public static class CommitRequest implements Serializable {
        private BigInteger knowledgeId;
        private BigInteger documentId;
        private List<String> previewSessionIds = new ArrayList<String>();

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public List<String> getPreviewSessionIds() {
            return previewSessionIds;
        }

        public void setPreviewSessionIds(List<String> previewSessionIds) {
            this.previewSessionIds = previewSessionIds;
        }
    }

    public static class SplitterProfileSaveRequest implements Serializable {
        private BigInteger knowledgeId;
        private String defaultStrategyCode;
        private Boolean autoRecommendEnabled;
        private String fallbackStrategyCode;
        private Map<String, Object> strategyProfiles = new LinkedHashMap<String, Object>();

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public String getDefaultStrategyCode() {
            return defaultStrategyCode;
        }

        public void setDefaultStrategyCode(String defaultStrategyCode) {
            this.defaultStrategyCode = defaultStrategyCode;
        }

        public Boolean getAutoRecommendEnabled() {
            return autoRecommendEnabled;
        }

        public void setAutoRecommendEnabled(Boolean autoRecommendEnabled) {
            this.autoRecommendEnabled = autoRecommendEnabled;
        }

        public String getFallbackStrategyCode() {
            return fallbackStrategyCode;
        }

        public void setFallbackStrategyCode(String fallbackStrategyCode) {
            this.fallbackStrategyCode = fallbackStrategyCode;
        }

        public Map<String, Object> getStrategyProfiles() {
            return strategyProfiles;
        }

        public void setStrategyProfiles(Map<String, Object> strategyProfiles) {
            this.strategyProfiles = strategyProfiles;
        }
    }

    public static class AnalyzeItem implements Serializable {
        private String filePath;
        private String fileName;
        private AnalysisResult analysis;
        private StrategyConfig strategyConfig = StrategyConfig.defaults();

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public AnalysisResult getAnalysis() {
            return analysis;
        }

        public void setAnalysis(AnalysisResult analysis) {
            this.analysis = analysis;
        }

        public StrategyConfig getStrategyConfig() {
            return strategyConfig;
        }

        public void setStrategyConfig(StrategyConfig strategyConfig) {
            this.strategyConfig = strategyConfig;
        }
    }

    public static class AnalyzeResponse implements Serializable {
        private Integer total;
        private List<AnalyzeItem> items = new ArrayList<AnalyzeItem>();

        public Integer getTotal() {
            return total;
        }

        public void setTotal(Integer total) {
            this.total = total;
        }

        public List<AnalyzeItem> getItems() {
            return items;
        }

        public void setItems(List<AnalyzeItem> items) {
            this.items = items;
        }
    }

    public static class PreviewSourceRange implements Serializable {
        private Integer start;
        private Integer end;

        public Integer getStart() {
            return start;
        }

        public void setStart(Integer start) {
            this.start = start;
        }

        public Integer getEnd() {
            return end;
        }

        public void setEnd(Integer end) {
            this.end = end;
        }
    }

    public static class PreviewChunkResult implements Serializable {
        private String answer;
        private Integer charCount;
        private String chunkId;
        private String chunkType;
        private String content;
        private String renderMarkdown;
        private List<String> headingPath = new ArrayList<String>();
        private Integer partNo;
        private Integer partTotal;
        private String question;
        private String sourceLabel;
        private Integer tokenEstimate;
        private List<String> warnings = new ArrayList<String>();
        private List<PreviewSourceRange> sourceRanges = new ArrayList<PreviewSourceRange>();

        public String getAnswer() {
            return answer;
        }

        public void setAnswer(String answer) {
            this.answer = answer;
        }

        public Integer getCharCount() {
            return charCount;
        }

        public void setCharCount(Integer charCount) {
            this.charCount = charCount;
        }

        public String getChunkId() {
            return chunkId;
        }

        public void setChunkId(String chunkId) {
            this.chunkId = chunkId;
        }

        public String getChunkType() {
            return chunkType;
        }

        public void setChunkType(String chunkType) {
            this.chunkType = chunkType;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getRenderMarkdown() {
            return renderMarkdown;
        }

        public void setRenderMarkdown(String renderMarkdown) {
            this.renderMarkdown = renderMarkdown;
        }

        public List<String> getHeadingPath() {
            return headingPath;
        }

        public void setHeadingPath(List<String> headingPath) {
            this.headingPath = headingPath;
        }

        public Integer getPartNo() {
            return partNo;
        }

        public void setPartNo(Integer partNo) {
            this.partNo = partNo;
        }

        public Integer getPartTotal() {
            return partTotal;
        }

        public void setPartTotal(Integer partTotal) {
            this.partTotal = partTotal;
        }

        public String getQuestion() {
            return question;
        }

        public void setQuestion(String question) {
            this.question = question;
        }

        public String getSourceLabel() {
            return sourceLabel;
        }

        public void setSourceLabel(String sourceLabel) {
            this.sourceLabel = sourceLabel;
        }

        public Integer getTokenEstimate() {
            return tokenEstimate;
        }

        public void setTokenEstimate(Integer tokenEstimate) {
            this.tokenEstimate = tokenEstimate;
        }

        public List<String> getWarnings() {
            return warnings;
        }

        public void setWarnings(List<String> warnings) {
            this.warnings = warnings;
        }

        public List<PreviewSourceRange> getSourceRanges() {
            return sourceRanges;
        }

        public void setSourceRanges(List<PreviewSourceRange> sourceRanges) {
            this.sourceRanges = sourceRanges;
        }
    }

    public static class PreviewFileResult implements Serializable {
        private String previewSessionId;
        private String filePath;
        private String fileName;
        private String normalizedContent;
        private String strategyCode;
        private String strategyLabel;
        private AnalysisResult analysis;
        private Integer totalChunks;
        private Integer totalWarnings;
        private List<PreviewChunkResult> chunks = new ArrayList<PreviewChunkResult>();

        public String getPreviewSessionId() {
            return previewSessionId;
        }

        public void setPreviewSessionId(String previewSessionId) {
            this.previewSessionId = previewSessionId;
        }

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public String getNormalizedContent() {
            return normalizedContent;
        }

        public void setNormalizedContent(String normalizedContent) {
            this.normalizedContent = normalizedContent;
        }

        public String getStrategyCode() {
            return strategyCode;
        }

        public void setStrategyCode(String strategyCode) {
            this.strategyCode = strategyCode;
        }

        public String getStrategyLabel() {
            return strategyLabel;
        }

        public void setStrategyLabel(String strategyLabel) {
            this.strategyLabel = strategyLabel;
        }

        public AnalysisResult getAnalysis() {
            return analysis;
        }

        public void setAnalysis(AnalysisResult analysis) {
            this.analysis = analysis;
        }

        public Integer getTotalChunks() {
            return totalChunks;
        }

        public void setTotalChunks(Integer totalChunks) {
            this.totalChunks = totalChunks;
        }

        public Integer getTotalWarnings() {
            return totalWarnings;
        }

        public void setTotalWarnings(Integer totalWarnings) {
            this.totalWarnings = totalWarnings;
        }

        public List<PreviewChunkResult> getChunks() {
            return chunks;
        }

        public void setChunks(List<PreviewChunkResult> chunks) {
            this.chunks = chunks;
        }
    }

    public static class PreviewResponse implements Serializable {
        private Integer totalFiles;
        private Integer totalChunks;
        private List<PreviewFileResult> items = new ArrayList<PreviewFileResult>();

        public Integer getTotalFiles() {
            return totalFiles;
        }

        public void setTotalFiles(Integer totalFiles) {
            this.totalFiles = totalFiles;
        }

        public Integer getTotalChunks() {
            return totalChunks;
        }

        public void setTotalChunks(Integer totalChunks) {
            this.totalChunks = totalChunks;
        }

        public List<PreviewFileResult> getItems() {
            return items;
        }

        public void setItems(List<PreviewFileResult> items) {
            this.items = items;
        }
    }

    public static class CommitFileResult implements Serializable {
        private String previewSessionId;
        private String fileName;
        private Boolean success;
        private String reason;
        private BigInteger documentId;
        private Integer chunkCount;

        public String getPreviewSessionId() {
            return previewSessionId;
        }

        public void setPreviewSessionId(String previewSessionId) {
            this.previewSessionId = previewSessionId;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public Boolean getSuccess() {
            return success;
        }

        public void setSuccess(Boolean success) {
            this.success = success;
        }

        public String getReason() {
            return reason;
        }

        public void setReason(String reason) {
            this.reason = reason;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public Integer getChunkCount() {
            return chunkCount;
        }

        public void setChunkCount(Integer chunkCount) {
            this.chunkCount = chunkCount;
        }
    }

    public static class CommitResponse implements Serializable {
        private Integer totalFiles;
        private Integer successCount;
        private Integer errorCount;
        private List<CommitFileResult> results = new ArrayList<CommitFileResult>();

        public Integer getTotalFiles() {
            return totalFiles;
        }

        public void setTotalFiles(Integer totalFiles) {
            this.totalFiles = totalFiles;
        }

        public Integer getSuccessCount() {
            return successCount;
        }

        public void setSuccessCount(Integer successCount) {
            this.successCount = successCount;
        }

        public Integer getErrorCount() {
            return errorCount;
        }

        public void setErrorCount(Integer errorCount) {
            this.errorCount = errorCount;
        }

        public List<CommitFileResult> getResults() {
            return results;
        }

        public void setResults(List<CommitFileResult> results) {
            this.results = results;
        }
    }

    public static class PreviewSession implements Serializable {
        private String sessionId;
        private BigInteger knowledgeId;
        private BigInteger documentId;
        private String filePath;
        private String fileName;
        private String sourceFormat;
        private StrategyConfig strategyConfig;
        private AnalysisResult analysis;
        private Document document;
        private List<DocumentChunk> documentChunks = new ArrayList<DocumentChunk>();
        private List<RagChunk> previewChunks = new ArrayList<RagChunk>();
        private Date createdAt;

        public String getSessionId() {
            return sessionId;
        }

        public void setSessionId(String sessionId) {
            this.sessionId = sessionId;
        }

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }

        public String getSourceFormat() {
            return sourceFormat;
        }

        public void setSourceFormat(String sourceFormat) {
            this.sourceFormat = sourceFormat;
        }

        public StrategyConfig getStrategyConfig() {
            return strategyConfig;
        }

        public void setStrategyConfig(StrategyConfig strategyConfig) {
            this.strategyConfig = strategyConfig;
        }

        public AnalysisResult getAnalysis() {
            return analysis;
        }

        public void setAnalysis(AnalysisResult analysis) {
            this.analysis = analysis;
        }

        public Document getDocument() {
            return document;
        }

        public void setDocument(Document document) {
            this.document = document;
        }

        public List<DocumentChunk> getDocumentChunks() {
            return documentChunks;
        }

        public void setDocumentChunks(List<DocumentChunk> documentChunks) {
            this.documentChunks = documentChunks;
        }

        public List<RagChunk> getPreviewChunks() {
            return previewChunks;
        }

        public void setPreviewChunks(List<RagChunk> previewChunks) {
            this.previewChunks = previewChunks;
        }

        public Date getCreatedAt() {
            return createdAt;
        }

        public void setCreatedAt(Date createdAt) {
            this.createdAt = createdAt;
        }
    }

    public static class TaskCreateRequest implements Serializable {
        private BigInteger knowledgeId;
        private String filePath;
        private String fileName;

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public String getFileName() {
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
    }

    public static class TaskCreateResponse implements Serializable {
        private BigInteger documentId;
        private BigInteger taskId;
        private String processStatus;

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public BigInteger getTaskId() {
            return taskId;
        }

        public void setTaskId(BigInteger taskId) {
            this.taskId = taskId;
        }

        public String getProcessStatus() {
            return processStatus;
        }

        public void setProcessStatus(String processStatus) {
            this.processStatus = processStatus;
        }
    }

    public static class TaskDetailResponse implements Serializable {
        private BigInteger taskId;
        private BigInteger documentId;
        private BigInteger knowledgeId;
        private String phase;
        private String status;
        private String processStatus;
        private Integer progressPercent;
        private Integer totalChunks;
        private Integer completedChunks;
        private Integer failedChunks;
        private String providerTaskId;
        private String errorSummary;
        private Date startedAt;
        private Date finishedAt;

        public BigInteger getTaskId() {
            return taskId;
        }

        public void setTaskId(BigInteger taskId) {
            this.taskId = taskId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public String getPhase() {
            return phase;
        }

        public void setPhase(String phase) {
            this.phase = phase;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getProcessStatus() {
            return processStatus;
        }

        public void setProcessStatus(String processStatus) {
            this.processStatus = processStatus;
        }

        public Integer getProgressPercent() {
            return progressPercent;
        }

        public void setProgressPercent(Integer progressPercent) {
            this.progressPercent = progressPercent;
        }

        public Integer getTotalChunks() {
            return totalChunks;
        }

        public void setTotalChunks(Integer totalChunks) {
            this.totalChunks = totalChunks;
        }

        public Integer getCompletedChunks() {
            return completedChunks;
        }

        public void setCompletedChunks(Integer completedChunks) {
            this.completedChunks = completedChunks;
        }

        public Integer getFailedChunks() {
            return failedChunks;
        }

        public void setFailedChunks(Integer failedChunks) {
            this.failedChunks = failedChunks;
        }

        public String getProviderTaskId() {
            return providerTaskId;
        }

        public void setProviderTaskId(String providerTaskId) {
            this.providerTaskId = providerTaskId;
        }

        public String getErrorSummary() {
            return errorSummary;
        }

        public void setErrorSummary(String errorSummary) {
            this.errorSummary = errorSummary;
        }

        public Date getStartedAt() {
            return startedAt;
        }

        public void setStartedAt(Date startedAt) {
            this.startedAt = startedAt;
        }

        public Date getFinishedAt() {
            return finishedAt;
        }

        public void setFinishedAt(Date finishedAt) {
            this.finishedAt = finishedAt;
        }
    }

    public static class TaskStartIndexRequest implements Serializable {
        private BigInteger knowledgeId;
        private BigInteger documentId;
        private String previewSessionId;

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }

        public String getPreviewSessionId() {
            return previewSessionId;
        }

        public void setPreviewSessionId(String previewSessionId) {
            this.previewSessionId = previewSessionId;
        }
    }

    public static class TaskStartIndexResponse implements Serializable {
        private BigInteger taskId;
        private String processStatus;

        public BigInteger getTaskId() {
            return taskId;
        }

        public void setTaskId(BigInteger taskId) {
            this.taskId = taskId;
        }

        public String getProcessStatus() {
            return processStatus;
        }

        public void setProcessStatus(String processStatus) {
            this.processStatus = processStatus;
        }
    }

    public static class TaskRetryRequest implements Serializable {
        private BigInteger knowledgeId;
        private BigInteger documentId;

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

        public void setKnowledgeId(BigInteger knowledgeId) {
            this.knowledgeId = knowledgeId;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

        public void setDocumentId(BigInteger documentId) {
            this.documentId = documentId;
        }
    }
}
