package com.lingyue.graph.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;

import java.util.Map;

/**
 * 文本分块实体
 * 用于存储文档分块后的文本片段，支持 RAG 检索
 *
 * @author lingyue
 * @since 2026-01-15
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "text_chunks", autoResultMap = true)
@Schema(description = "文本分块实体")
public class TextChunk extends SimpleModel {

    @Schema(description = "文档ID")
    @TableField("document_id")
    private String documentId;

    @Schema(description = "文本存储ID")
    @TableField("text_storage_id")
    private String textStorageId;

    @Schema(description = "分块索引（在文档中的顺序）")
    @TableField("chunk_index")
    private Integer chunkIndex;

    @Schema(description = "分块文本内容")
    @TableField("content")
    private String content;

    @Schema(description = "估算的Token数量")
    @TableField("token_count")
    private Integer tokenCount;

    @Schema(description = "元数据（页码、段落位置等）")
    @TableField(value = "metadata", typeHandler = PostgreSqlJsonbTypeHandler.class)
    private Map<String, Object> metadata;
}
