package com.zhengmeng.ocrplatform.task;

import com.zhengmeng.ocrplatform.document.OcrDocumentEntity;

import java.time.LocalDateTime;
import java.util.List;

public record OcrTaskSummary(
        String taskId,
        String clientCode,
        TaskStatus status,
        String sourceSystem,
        String businessType,
        String templateCode,
        String originalFilename,
        long fileSize,
        String sha256,
        Integer attemptCount,
        LocalDateTime createdAt,
        LocalDateTime updatedAt
) {
    public static OcrTaskSummary from(OcrTaskEntity task, List<OcrDocumentEntity> documents) {
        OcrDocumentEntity firstDocument = documents.isEmpty() ? null : documents.getFirst();
        return new OcrTaskSummary(
                task.getTaskId(),
                task.getClientCode(),
                task.getStatus(),
                task.getSourceSystem(),
                task.getBusinessType(),
                task.getTemplateCode(),
                firstDocument == null ? null : firstDocument.getOriginalFilename(),
                firstDocument == null ? 0 : firstDocument.getFileSize(),
                firstDocument == null ? null : firstDocument.getSha256(),
                task.getAttemptCount(),
                task.getCreatedAt(),
                task.getUpdatedAt()
        );
    }
}
