package com.lingyue.document.entity;

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

/**
 * 文档实体标注
 * 表示文档中被标记的一个实体/要素（人名、机构、数据、地点等）
 * 
 * @author lingyue
 * @since 2026-01-21
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "document_entities", autoResultMap = true)
@Schema(description = "文档实体标注")
public class DocumentEntity extends SimpleModel {
    
    @Schema(description = "文档ID")
    @TableField("document_id")
    private String documentId;
    
    @Schema(description = "所属块ID")
    @TableField("block_id")
    private String blockId;
    
    @Schema(description = "实体名称/文本")
    @TableField("name")
    private String name;
    
    @Schema(description = "实体类型", example = "PERSON/ORG/LOC/DATE/NUMBER/MONEY/CONCEPT/DATA")
    @TableField("entity_type")
    private String entityType;
    
    @Schema(description = "实体值（标准化后的值）")
    @TableField("value")
    private String value;
    
    @Schema(description = "在块内的字符起始位置")
    @TableField("block_char_start")
    private Integer blockCharStart;
    
    @Schema(description = "在块内的字符结束位置")
    @TableField("block_char_end")
    private Integer blockCharEnd;
    
    @Schema(description = "在全文中的字符起始位置（快照，编辑后可能失效）")
    @TableField("global_char_start")
    private Integer globalCharStart;
    
    @Schema(description = "在全文中的字符结束位置（快照，编辑后可能失效）")
    @TableField("global_char_end")
    private Integer globalCharEnd;
    
    @Schema(description = "实体前文本锚点（用于重定位）")
    @TableField("anchor_before")
    private String anchorBefore;
    
    @Schema(description = "实体后文本锚点（用于重定位）")
    @TableField("anchor_after")
    private String anchorAfter;
    
    @Schema(description = "来源", example = "auto/manual")
    @TableField("source")
    private String source = "auto";
    
    @Schema(description = "置信度 0-1")
    @TableField("confidence")
    private Double confidence;
    
    @Schema(description = "是否已确认")
    @TableField("confirmed")
    private Boolean confirmed = false;
    
    @Schema(description = "关联的图节点ID")
    @TableField("graph_node_id")
    private String graphNodeId;
    
    @Schema(description = "元数据", example = "{\"context\": \"...\", \"suggestion\": \"...\"}")
    @TableField(value = "metadata", typeHandler = PostgreSqlJsonbTypeHandler.class)
    private Object metadata;
}
