import request from '@/utils/request'

export const api = {
  // page: '/file/cloudStorage/page/neglect/tenant',
  page: '/process/project/file/page',
  // abandon: '/file/cloudStorage/hide/file',
  abandon: '/process/project/file/hide/page',
  remove: '/file/cloudStorage/delete/file',
  add: '/file/cloudStorage/mkdir',

  upload: '/file/cloudStorage/upload/directory',

  // recover: '/file/cloudStorage/recover/file',
  recover: '/process/project/file/recover/file',
  uploadInDirectoryId: '/file/cloudStorage/upload/directory',
  batchDownload: '/file/cloudStorage/batch/download',
  download: '/file/cloudStorage/download'
}

// 分页获取项目文件列表
export function fetchDirectoryPage(params) {
  return request({
    url: api.page,
    method: 'get',
    params
  })
}

export function downloadFileById(data) {
  return request({
    url: api.download,
    method: 'post',
    data
  })
}

// 移除到回收站
export function abandonFile(data) {
  return request({
    url: api.abandon,
    method: 'post',
    data
  })
}
// 彻底删除文件
export function removeFile(data) {
  return request({
    url: api.remove,
    method: 'post',
    data
  })
}

// 回收站恢复文件到文件列表/文件夹
export function recoverFile(data) {
  return request({
    url: api.recover,
    method: 'post',
    data
  })
}

export function batchDownloadFile(data) {
  return request({
    url: api.batchDownload,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

// 新建文件夹
export function addDirectory({ dirName, parentId }) {
  return request({
    url: `${api.add}?dirName=${dirName}&parentId=${parentId}`,
    method: 'post'
  })
}

// 上传文件
export function uploadFileInDir(directoryId) {
  return request({
    url: `${api.upload}?directoryId=${directoryId}`,
    method: 'post'
  })
}
