package com.lingyue.graph.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lingyue.graph.entity.Rule;
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 RuleRepository extends BaseMapper<Rule> {
    
    /**
     * 根据用户ID查询规则列表
     * 
     * @param userId 用户ID
     * @return 规则列表
     */
    @Select("SELECT * FROM rules WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Rule> findByUserId(@Param("userId") String userId);
    
    /**
     * 根据用户ID和状态查询规则
     * 
     * @param userId 用户ID
     * @param status 状态
     * @return 规则列表
     */
    @Select("SELECT * FROM rules WHERE user_id = #{userId} AND status = #{status} ORDER BY create_time DESC")
    List<Rule> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
    
    /**
     * 根据入口节点ID查询规则
     * 
     * @param entryNodeId 入口节点ID
     * @return 规则列表
     */
    @Select("SELECT * FROM rules WHERE entry_node_id = #{entryNodeId}")
    List<Rule> findByEntryNodeId(@Param("entryNodeId") String entryNodeId);
}
