/**
 * @description 知识库相关API
 * @author yslg
 * @since 2025-10-15
 */

import { api } from '@/apis/index';
import type { AiKnowledge, ResultDomain } from '@/types';

/**
 * 知识库API服务
 */
export const knowledgeApi = {
  /**
   * 获取知识库列表
   * @returns Promise<ResultDomain<AiKnowledge>>
   */
  async getKnowledgeList(): Promise<ResultDomain<AiKnowledge>> {
    const response = await api.get<AiKnowledge>('/ai/knowledge/list');
    return response.data;
  },

  /**
   * 创建知识库条目
   * @param knowledge 知识库数据
   * @returns Promise<ResultDomain<AiKnowledge>>
   */
  async createKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
    const response = await api.post<AiKnowledge>('/ai/knowledge/create', knowledge);
    return response.data;
  },

  /**
   * 更新知识库条目
   * @param knowledge 知识库数据
   * @returns Promise<ResultDomain<AiKnowledge>>
   */
  async updateKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
    const response = await api.put<AiKnowledge>('/ai/knowledge/update', knowledge);
    return response.data;
  },

  /**
   * 删除知识库条目
   * @param knowledgeID 知识库ID
   * @returns Promise<ResultDomain<boolean>>
   */
  async deleteKnowledge(knowledgeID: string): Promise<ResultDomain<boolean>> {
    const response = await api.delete<boolean>(`/ai/knowledge/${knowledgeID}`);
    return response.data;
  }
};
