package com.lingyue.graph.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lingyue.graph.entity.GraphNode;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 图节点Repository
 * 
 * @author lingyue
 * @since 2026-01-14
 */
@Mapper
public interface GraphNodeRepository extends BaseMapper<GraphNode> {
    
    /**
     * 根据文档ID查询节点列表
     * 
     * @param documentId 文档ID
     * @return 节点列表
     */
    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} ORDER BY level, create_time")
    List<GraphNode> findByDocumentId(@Param("documentId") String documentId);
    
    /**
     * 根据父节点ID查询子节点
     * 
     * @param parentId 父节点ID
     * @return 子节点列表
     */
    @Select("SELECT * FROM graph_nodes WHERE parent_id = #{parentId} ORDER BY create_time")
    List<GraphNode> findByParentId(@Param("parentId") String parentId);
    
    /**
     * 根据文档ID和类型查询节点
     * 
     * @param documentId 文档ID
     * @param type 节点类型
     * @return 节点列表
     */
    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} AND type = #{type}")
    List<GraphNode> findByDocumentIdAndType(@Param("documentId") String documentId, 
                                            @Param("type") String type);
    
    /**
     * 根据用户ID查询节点列表
     * 
     * @param userId 用户ID
     * @return 节点列表
     */
    @Select("SELECT * FROM graph_nodes WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<GraphNode> findByUserId(@Param("userId") String userId);
}
