package com.lingyue.parse.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lingyue.common.domain.entity.SimpleModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * 解析任务实体
 * 
 * 阶段流程：
 * 1. upload - 文件上传
 * 2. parse - 文本解析（OCR/Word提取）
 * 3. rag - RAG向量化
 * 4. structured - 结构化解析（图片/表格）
 * 5. ner - NER实体提取
 * 6. graph - 图数据库构建
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "parse_tasks", autoResultMap = true)
@Schema(description = "解析任务实体")
public class ParseTask extends SimpleModel {
    
    @Schema(description = "文档ID")
    @TableField("document_id")
    private String documentId;
    
    @Schema(description = "状态: pending/processing/completed/failed")
    @TableField("status")
    private String status = "pending";
    
    @Schema(description = "整体进度(0-100)")
    @TableField("progress")
    private Integer progress = 0;
    
    @Schema(description = "当前步骤: upload/parse/rag/structured/ner/graph")
    @TableField("current_step")
    private String currentStep;
    
    @Schema(description = "错误消息")
    @TableField("error_message")
    private String errorMessage;
    
    @Schema(description = "选项")
    @TableField(value = "options", typeHandler = com.lingyue.common.mybatis.PostgreSqlJsonbTypeHandler.class)
    private Object options;
    
    @Schema(description = "开始时间")
    @TableField("started_at")
    private Date startedAt;
    
    @Schema(description = "完成时间")
    @TableField("completed_at")
    private Date completedAt;
    
    // ==================== 各阶段状态 ====================
    
    @Schema(description = "解析阶段状态: pending/processing/completed/failed")
    @TableField("parse_status")
    private String parseStatus = "pending";
    
    @Schema(description = "解析阶段进度(0-100)")
    @TableField("parse_progress")
    private Integer parseProgress = 0;
    
    @Schema(description = "RAG阶段状态")
    @TableField("rag_status")
    private String ragStatus = "pending";
    
    @Schema(description = "RAG阶段进度")
    @TableField("rag_progress")
    private Integer ragProgress = 0;
    
    @Schema(description = "结构化解析状态")
    @TableField("structured_status")
    private String structuredStatus = "pending";
    
    @Schema(description = "结构化解析进度")
    @TableField("structured_progress")
    private Integer structuredProgress = 0;
    
    @Schema(description = "结构化解析结果: 元素数量")
    @TableField("structured_element_count")
    private Integer structuredElementCount;
    
    @Schema(description = "结构化解析结果: 图片数量")
    @TableField("structured_image_count")
    private Integer structuredImageCount;
    
    @Schema(description = "结构化解析结果: 表格数量")
    @TableField("structured_table_count")
    private Integer structuredTableCount;
    
    @Schema(description = "NER阶段状态")
    @TableField("ner_status")
    private String nerStatus = "pending";
    
    @Schema(description = "NER阶段进度")
    @TableField("ner_progress")
    private Integer nerProgress = 0;
    
    @Schema(description = "NER任务ID（Python服务返回）")
    @TableField("ner_task_id")
    private String nerTaskId;
    
    @Schema(description = "NER结果: 实体数量")
    @TableField("ner_entity_count")
    private Integer nerEntityCount;
    
    @Schema(description = "NER结果: 关系数量")
    @TableField("ner_relation_count")
    private Integer nerRelationCount;
    
    @Schema(description = "图构建阶段状态")
    @TableField("graph_status")
    private String graphStatus = "pending";
    
    @Schema(description = "图构建阶段进度")
    @TableField("graph_progress")
    private Integer graphProgress = 0;
}
