import { http as request } from './http'

export const knowledgeApi = {
  // Get List
  async getKnowledgeBases(params) {
    const { data } = await request.get('api/knowledge-bases', { params })
    return data.data
  },
  
  // Create
  async createKnowledgeBase(data) {
    const { data: res } = await request.post('api/knowledge-bases', data)
    return res.data
  },

  // Upload Document
  async uploadDocument(id, file) {
    const formData = new FormData()
    formData.append('file', file)
    const { data } = await request.post(`api/knowledge-bases/${id}/upload`, formData)
    return data
  },

  // List Documents
  async listDocuments(id) {
    const { data } = await request.get(`api/knowledge-bases/${id}/documents`)
    return data.data
  },

  // Delete Document
  async deleteDocument(id, docId) {
    const { data } = await request.delete(`api/knowledge-bases/${id}/documents/${docId}`)
    return data.data
  },

  // Rebuild Vector Store
  async rebuildVectorStore(id) {
    const { data } = await request.post(`api/knowledge-bases/${id}/rebuild`)
    return data.data
  },

  // Delete
  async deleteKnowledgeBase(id) {
    const { data } = await request.delete(`api/knowledge-bases/${id}`)
    return data.data
  }
}
