import request from '@/utils/request'

export function getCategoryTree() {
  return request.get('/data/categories')
}

export function createCategory(payload) {
  return request.post('/data/categories', payload)
}

export function updateCategory(categoryId, payload) {
  return request.put(`/data/categories/${categoryId}`, payload)
}

export function deleteCategory(categoryId) {
  return request.delete(`/data/categories/${categoryId}`)
}

export function getDataFiles(params) {
  return request.get('/data/files', { params })
}

export function uploadDataFile(formData) {
  return request.post('/data/files/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}

export function deleteDataFile(fileId) {
  return request.delete(`/data/files/${fileId}`)
}

export function getFileRecords(fileId, params) {
  return request.get(`/data/files/${fileId}/records`, { params })
}

export function downloadDataTemplate() {
  return request.get('/data/files/template', {
    responseType: 'blob',
  })
}
