/*
 * @Author: ysh
 * @Date: 2025-06-30 09:56:10
 * @LastEditors: wrh
 * @LastEditTime: 2026-04-21 13:42:00
 */
import request from '@/utils/request'

// 查询知识库列表
export function listKnowledge() {
  return request({
    url: '/llm/knowledge/list',
    method: 'get',
  })
}

// 获取上传进度
export function getProcessValue() {
  return request({
    url: '/llm/knowledge/getProcess',
    method: 'get'
  })
}

// 根据collectionName查询知识库列表
export function listKnowLedgeByCollectionName(collectionName) {
  return request({
    url: '/llm/knowledge/listByName',
    method: 'get',
    params: collectionName
  })
}

// 新增知识库
export function addKnowledge(collectionName, description) {
  return request({
    url: '/llm/knowledge/create',
    method: 'post',
    params: { collectionName, description }
  })
}

// 修改知识库
export function updateKnowledge(collectionName, newCollectionName) {
  return request({
    url: '/llm/knowledge/modify',
    method: 'post',
    params: { collectionName, newCollectionName }
  })
}

// 删除知识库
export function delKnowledge(collectionName) {
  return request({
    url: '/llm/knowledge/remove',
    method: 'delete',
    params: { collectionName }
  })
}

// 插入知识库文件
export function insertKnowledgeFile(fileList, collectionName) {
  const formData = new FormData()
  for(let f of fileList){
    formData.append('fileList', f)
  }
  formData.append('collectionName', collectionName)
  return request({
    url: '/llm/knowledge/insertDocument',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 查看知识库文件
export function listKnowledgeDocument(collectionName, fileType) {
  return request({
    url: '/llm/knowledge/listDocument',
    method: 'get',
    params: { collectionName, fileType }
  })
}

// 删除知识库文件
export function deleteKnowledgeFile(fileName,collectionName) {
  return request({
    url: '/llm/knowledge/removeDocument',
    method: 'delete',
    params: { fileName, collectionName }
  })
}

// 列出所有的title
export function listTiles(collectionName) {
  return request({
    url: '/llm/knowledge/listTiles',
    method: 'get',
    params: { collectionName }
  })
}

// 根据title名查询相关content
export function listByTitle(collectionName, title) {
  return request({
    url: '/llm/knowledge/listByTitle',
    method: 'get',
    params: { collectionName, title }
  })
}

// 根据文件名获取标题列表
export function listTilesByFile(collectionName, fileName) {
  return request({
    url: '/llm/knowledge/listTilesByFile',
    method: 'get',
    params: { collectionName, fileName }
  })
}
