package tech.easyflow.ai.documentimport;

import com.easyagents.rag.ingestion.model.StrategyConfig;

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

/**
 * 知识库 Public API 批量导入数据对象。
 *
 * @author Codex
 * @since 2026-08-02
 */
public final class PublicDocumentImportDtos {

    private PublicDocumentImportDtos() {
    }

    /**
     * Multipart 元数据。
     */
    public static class BatchMetadata implements Serializable {
        private BigInteger knowledgeId;
        private StrategyConfig chunkStrategy = StrategyConfig.defaults();
        private String duplicatePolicy = "SKIP";
        private List<DocumentImportBatchDtos.ManifestItem> files = new ArrayList<>();

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

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

        public StrategyConfig getChunkStrategy() {
            return chunkStrategy;
        }

        public void setChunkStrategy(StrategyConfig chunkStrategy) {
            this.chunkStrategy = chunkStrategy == null
                ? StrategyConfig.defaults()
                : chunkStrategy;
        }

        public String getDuplicatePolicy() {
            return duplicatePolicy;
        }

        public void setDuplicatePolicy(String duplicatePolicy) {
            this.duplicatePolicy = duplicatePolicy;
        }

        public List<DocumentImportBatchDtos.ManifestItem> getFiles() {
            return files;
        }

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

    /**
     * 批量提交响应。
     */
    public static class SubmitResponse implements Serializable {
        private BigInteger taskId;
        private String status;
        private Integer totalCount;
        private Long totalBytes;
        private Date createdAt;

        public BigInteger getTaskId() {
            return taskId;
        }

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

        public String getStatus() {
            return status;
        }

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

        public Integer getTotalCount() {
            return totalCount;
        }

        public void setTotalCount(Integer totalCount) {
            this.totalCount = totalCount;
        }

        public Long getTotalBytes() {
            return totalBytes;
        }

        public void setTotalBytes(Long totalBytes) {
            this.totalBytes = totalBytes;
        }

        public Date getCreatedAt() {
            return createdAt;
        }

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

    /**
     * 批次计数。
     */
    public static class Counts implements Serializable {
        private Integer total;
        private Integer completed;
        private Integer processing;
        private Integer pending;
        private Integer failed;
        private Integer skipped;
        private Integer retryableFailed;

        public Integer getTotal() {
            return total;
        }

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

        public Integer getCompleted() {
            return completed;
        }

        public void setCompleted(Integer completed) {
            this.completed = completed;
        }

        public Integer getProcessing() {
            return processing;
        }

        public void setProcessing(Integer processing) {
            this.processing = processing;
        }

        public Integer getPending() {
            return pending;
        }

        public void setPending(Integer pending) {
            this.pending = pending;
        }

        public Integer getFailed() {
            return failed;
        }

        public void setFailed(Integer failed) {
            this.failed = failed;
        }

        public Integer getSkipped() {
            return skipped;
        }

        public void setSkipped(Integer skipped) {
            this.skipped = skipped;
        }

        public Integer getRetryableFailed() {
            return retryableFailed;
        }

        public void setRetryableFailed(Integer retryableFailed) {
            this.retryableFailed = retryableFailed;
        }
    }

    /**
     * 文件失败信息。
     */
    public static class ItemError implements Serializable {
        private String code;
        private String message;

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }

    /**
     * 批次文件状态记录。
     */
    public static class ItemRecord implements Serializable {
        private String fileKey;
        private String relativePath;
        private BigInteger documentId;
        private String stage;
        private String status;
        private Integer attemptCount;
        private Boolean retryable;
        private ItemError error;

        public String getFileKey() {
            return fileKey;
        }

        public void setFileKey(String fileKey) {
            this.fileKey = fileKey;
        }

        public String getRelativePath() {
            return relativePath;
        }

        public void setRelativePath(String relativePath) {
            this.relativePath = relativePath;
        }

        public BigInteger getDocumentId() {
            return documentId;
        }

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

        public String getStage() {
            return stage;
        }

        public void setStage(String stage) {
            this.stage = stage;
        }

        public String getStatus() {
            return status;
        }

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

        public Integer getAttemptCount() {
            return attemptCount;
        }

        public void setAttemptCount(Integer attemptCount) {
            this.attemptCount = attemptCount;
        }

        public Boolean getRetryable() {
            return retryable;
        }

        public void setRetryable(Boolean retryable) {
            this.retryable = retryable;
        }

        public ItemError getError() {
            return error;
        }

        public void setError(ItemError error) {
            this.error = error;
        }
    }

    /**
     * 批次文件状态分页。
     */
    public static class ItemPage implements Serializable {
        private Long pageNumber;
        private Long pageSize;
        private Long total;
        private List<ItemRecord> records = new ArrayList<>();

        public Long getPageNumber() {
            return pageNumber;
        }

        public void setPageNumber(Long pageNumber) {
            this.pageNumber = pageNumber;
        }

        public Long getPageSize() {
            return pageSize;
        }

        public void setPageSize(Long pageSize) {
            this.pageSize = pageSize;
        }

        public Long getTotal() {
            return total;
        }

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

        public List<ItemRecord> getRecords() {
            return records;
        }

        public void setRecords(List<ItemRecord> records) {
            this.records = records;
        }
    }

    /**
     * 批次状态响应。
     */
    public static class StatusResponse implements Serializable {
        private BigInteger taskId;
        private BigInteger knowledgeId;
        private String status;
        private Integer progressPercent;
        private Counts counts;
        private Boolean canRetry;
        private ItemPage items;

        public BigInteger getTaskId() {
            return taskId;
        }

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

        public BigInteger getKnowledgeId() {
            return knowledgeId;
        }

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

        public String getStatus() {
            return status;
        }

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

        public Integer getProgressPercent() {
            return progressPercent;
        }

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

        public Counts getCounts() {
            return counts;
        }

        public void setCounts(Counts counts) {
            this.counts = counts;
        }

        public Boolean getCanRetry() {
            return canRetry;
        }

        public void setCanRetry(Boolean canRetry) {
            this.canRetry = canRetry;
        }

        public ItemPage getItems() {
            return items;
        }

        public void setItems(ItemPage items) {
            this.items = items;
        }
    }

    /**
     * 异常任务重试请求。
     */
    public static class RetryRequest implements Serializable {
        private BigInteger taskId;
        private List<String> fileKeys;

        public BigInteger getTaskId() {
            return taskId;
        }

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

        public List<String> getFileKeys() {
            return fileKeys;
        }

        public void setFileKeys(List<String> fileKeys) {
            this.fileKeys = fileKeys;
        }
    }

    /**
     * 异常任务重试响应。
     */
    public static class RetryResponse implements Serializable {
        private BigInteger taskId;
        private String status;
        private Integer retriedCount;

        public BigInteger getTaskId() {
            return taskId;
        }

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

        public String getStatus() {
            return status;
        }

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

        public Integer getRetriedCount() {
            return retriedCount;
        }

        public void setRetriedCount(Integer retriedCount) {
            this.retriedCount = retriedCount;
        }
    }
}
