import request from '@/utils/request'

// 知识库API
export const knowledgeApi = {
  // 获取知识库列表
  getList: (params) => {
    return request({
      url: '/knowledge/base/list',
      method: 'get',
      params
    })
  },

  // 搜索知识
  search: (keyword, industryType) => {
    return request({
      url: '/knowledge/base/search',
      method: 'get',
      params: { keyword, industryType }
    })
  },

  // 根据ID获取
  getById: (id) => {
    return request({
      url: `/knowledge/base/${id}`,
      method: 'get'
    })
  },

  // 创建知识
  create: (data) => {
    return request({
      url: '/knowledge/base',
      method: 'post',
      data
    })
  },

  // 更新知识
  update: (id, data) => {
    return request({
      url: `/knowledge/base/${id}`,
      method: 'put',
      data
    })
  },

  // 删除知识
  delete: (id) => {
    return request({
      url: `/knowledge/base/${id}`,
      method: 'delete'
    })
  },

  // 审核知识
  audit: (id, auditStatus, comment) => {
    return request({
      url: `/knowledge/base/${id}/audit`,
      method: 'post',
      params: { auditStatus, comment }
    })
  },

  // 同步到FastGPT
  syncToFastGpt: (id) => {
    return request({
      url: `/knowledge/base/${id}/sync-fastgpt`,
      method: 'post'
    })
  },

  // 从聊天记录提取知识
  extractFromChat: (chatRecordId, question, answer) => {
    return request({
      url: '/knowledge/base/extract-from-chat',
      method: 'post',
      params: { chatRecordId, question, answer }
    })
  },

  // 双知识库校验
  dualValidation: (query, fastgptResult) => {
    return request({
      url: '/knowledge/base/dual-validation',
      method: 'post',
      params: { query, fastgptResult }
    })
  }
}

// 知识审核API
export const knowledgeAuditApi = {
  // 获取待审核列表
  getPendingList: () => {
    return request({
      url: '/knowledge/audit/pending',
      method: 'get'
    })
  },

  // 获取已审核列表
  getAuditedList: () => {
    return request({
      url: '/knowledge/audit/audited',
      method: 'get'
    })
  },

  // 获取优化建议列表
  getSuggestionList: (params) => {
    return request({
      url: '/knowledge/suggestion/list',
      method: 'get',
      params
    })
  },

  // 通过审核
  approve: (id, comment) => {
    return request({
      url: `/knowledge/audit/${id}/approve`,
      method: 'post',
      params: { comment }
    })
  },

  // 驳回审核
  reject: (id, comment) => {
    return request({
      url: `/knowledge/audit/${id}/reject`,
      method: 'post',
      params: { comment }
    })
  },

  // 批量审核
  batchAudit: (data) => {
    return request({
      url: '/knowledge/audit/batch',
      method: 'post',
      data
    })
  },

  // 应用优化建议
  applySuggestion: (id) => {
    return request({
      url: `/knowledge/suggestion/${id}/apply`,
      method: 'post'
    })
  },

  // 忽略优化建议
  ignoreSuggestion: (id) => {
    return request({
      url: `/knowledge/suggestion/${id}/ignore`,
      method: 'post'
    })
  }
}
