import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { AiKnowledgeBaseVO, AiKnowledgeBaseForm, AiKnowledgeBaseQuery } from '@/api/ai/skill/aiKnowledgeBase/types';

/**
 * 查询AI知识库列表
 * @param query
 * @returns {*}
 */

export const listAiKnowledgeBase = (query?: AiKnowledgeBaseQuery): AxiosPromise<AiKnowledgeBaseVO[]> => {
  return request({
    url: '/ai/aiKnowledgeBase/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询AI知识库详细
 * @param knowledgeBaseId
 */
export const getAiKnowledgeBase = (knowledgeBaseId: string | number): AxiosPromise<AiKnowledgeBaseVO> => {
  return request({
    url: '/ai/aiKnowledgeBase/' + knowledgeBaseId,
    method: 'get'
  });
};

/**
 * 新增AI知识库
 * @param data
 */
export const addAiKnowledgeBase = (data: AiKnowledgeBaseForm) => {
  return request({
    url: '/ai/aiKnowledgeBase',
    method: 'post',
    data: data
  });
};

/**
 * 修改AI知识库
 * @param data
 */
export const updateAiKnowledgeBase = (data: AiKnowledgeBaseForm) => {
  return request({
    url: '/ai/aiKnowledgeBase',
    method: 'put',
    data: data
  });
};

/**
 * 删除AI知识库
 * @param knowledgeBaseId
 */
export const delAiKnowledgeBase = (knowledgeBaseId: string | number | Array<string | number>) => {
  return request({
    url: '/ai/aiKnowledgeBase/' + knowledgeBaseId,
    method: 'delete'
  });
};


/**
 * 下拉框查询AI知识库列表
 * @param query
 * @returns {*}
 */
export function getAiKnowledgeBaseList (query) {
    return request({
        url: '/ai/aiKnowledgeBase/getAiKnowledgeBaseList',
        method: 'get',
        params: query
    });
};




/**
 * 知识库文件上传切分后向量化
 * @param data 知识库切片内容
 */
export const vectorizeKnowledgeContent = (data: FormData) => {
  return request({
    url: '/ai/aiKnowledgeBase/vectorizeKnowledgeContent',
    method: 'post',
    data: data
  });
};

/**
 * 获取AI知识库内容列表
 * @param query
 * @returns {*}
 */
export function listAiKnowledgeContent (query) {
  return request({
    url: '/ai/aiKnowledgeBase/listAiKnowledgeContent',
    method: 'get',
    params: query
  });
};


/**
 * 删除AI知识库内容,连同向量库内容一同删除
 * @param knowledgeBaseId
 * @param knowledgeContentId
 */
export const delAiKnowledgeContent = (knowledgeBaseId: string | number ,knowledgeContentId: string | number | Array<string | number>) => {
  return request({
    url: '/ai/aiKnowledgeBase/deleteKnowledgeContent/' + knowledgeBaseId + '/' + knowledgeContentId,
    method: 'post'
  });
};


/**
 * 删除知识库内容文件
 * @param knowledgeContentId
 */
export const removeContentFile = (knowledgeContentId: string | number) => {
  return request({
    url: '/ai/aiKnowledgeBase/removeContentFile/' +  knowledgeContentId,
    method: 'post'
  });
};

/**
 * 获取AI知识库内容分段列表
 * @param query
 * @returns {*}
 */
export function getKnowledgeContentFragmentList (query) {
  return request({
    url: '/ai/aiKnowledgeBase/getKnowledgeContentFragmentList',
    method: 'get',
    params: query
  });
};
