package org.xyzh.ai.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.xyzh.api.ai.dto.TbKnowledge;
import org.xyzh.common.core.page.PageParam;

import java.util.List;

/**
 * @description 知识库数据访问层
 * @filename KnowledgeMapper.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-12-17
 */
@Mapper
public interface TbKnowledgeMapper {

    /**
     * 插入知识库
     */
    int insertKnowledge(TbKnowledge knowledge);

    /**
     * 更新知识库
     */
    int updateKnowledge(TbKnowledge knowledge);

    /**
     * 逻辑删除知识库
     */
    int deleteKnowledge(TbKnowledge knowledge);

    int updateKnowledgeFileCount(@Param("knowledgeId") String knowledgeId, @Param("num") Integer num);

    /**
     * 根据ID查询知识库
     */
    TbKnowledge selectKnowledgeById(@Param("knowledgeId") String knowledgeId);

    /**
     * 根据DifyDatasetId查询知识库
     */
    TbKnowledge selectKnowledgeByDifyId(@Param("difyDatasetId") String difyDatasetId);

    /**
     * 查询知识库列表
     */
    List<TbKnowledge> selectKnowledgeList(@Param("filter") TbKnowledge filter);

    /**
     * 分页查询知识库
     */
    List<TbKnowledge> selectKnowledgePage(
            @Param("filter") TbKnowledge filter,
            @Param("pageParam") PageParam pageParam
    );

    /**
     * 统计知识库数量
     */
    long countKnowledges(@Param("filter") TbKnowledge filter);
}
