import request from '@/utils/request'

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

// 查询洪水知识库详细
export function getKnowledge(knowledgeId) {
  return request({
    url: '/flood/knowledge/' + knowledgeId,
    method: 'get'
  })
}

// 新增洪水知识库
export function addKnowledge(data) {
  return request({
    url: '/flood/knowledge',
    method: 'post',
    data: data
  })
}

// 修改洪水知识库
export function updateKnowledge(data) {
  return request({
    url: '/flood/knowledge',
    method: 'put',
    data: data
  })
}

// 删除洪水知识库
export function delKnowledge(knowledgeId) {
  return request({
    url: '/flood/knowledge/' + knowledgeId,
    method: 'delete'
  })
}

// 查询知识库文件列表
export function listKnowledgeFiles(knowledgeId) {
  return request({
    url: '/flood/knowledge/files/' + knowledgeId,
    method: 'get'
  })
}

// 上传知识库文件
export function uploadKnowledgeFile(data) {
  return request({
    url: '/flood/knowledge/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除知识库文件
export function delKnowledgeFile(fileId) {
  return request({
    url: '/flood/knowledge/files/' + fileId,
    method: 'delete'
  })
}

// 预览文件
export function previewFile(fileId) {
  return request({
    url: '/flood/knowledge/preview/' + fileId,
    method: 'get'
  })
}

// 获取 kkFileView 预览URL
export function getKkFileViewUrl(fileId, token) {
  const params = token ? { token: token } : {};
  return request({
    url: '/flood/knowledge/previewKkFileView/' + fileId,
    method: 'get',
    params: params
  })
}
