import request from '@/utils/request'

/**
 * 附件
 * @param {*} data
 */
export const privateFileSaveUrl = '/api/v1/mp/image/remote/upload/commpress/1'

export const publicFileSaveUrl = '/api/v1/mp/image/remote/upload/commpress/0'

// 云端非公开可访问的BaseUrl
export const privateFileGetUrl = '/api/v1/mp/file/remote/download?name='

// 云端公开可访问的BaseUrl
export const publicFileGetUrl = process.env.NODE_ENV === "production" ? 'https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/':'https://mp-public-test-1307117429.cos.ap-shanghai.myqcloud.com/'

/**
 * Put 方式上传图片
 */
export function publicFileSaveAPI(data, config = {}) {
  var formData  = new FormData()
  Object.keys(data).forEach(key => {
    formData.append(key, data[key])
  })
  return request({
    url: '/api/v1/mp/image/remote/upload/commpress/0',
    method: 'put',
    data: formData ,
    ...config,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * Put 方式上传图片
 */
export function privateFileSaveAPI(data, config = {}) {
  var formData  = new FormData()
  Object.keys(data).forEach(key => {
    formData.append(key, data[key])
  })
  return request({
    url: '/api/v1/mp/image/remote/upload/commpress/1',
    method: 'put',
    data: formData ,
    ...config,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * Put 方式上传文件
 */
export function uploadFileRequest(data, bizType, config = {}) {
  var formData  = new FormData()
  Object.keys(data).forEach(key => {
    formData.append(key, data[key])
  })
  return request({
    url: '/api/v1/mp/file/remote/upload/' + bizType,
    method: 'put',
    data: formData ,
    ...config,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function downloadFileAPI(url) {
  return request({
    url: url,
    method: 'get',
    data: {},
    responseType: 'blob'
  })
}


/**
 * Post 方式上传文件
 */
export function importFileSaveAPI(data, config = {}) {
  var formData  = new FormData()
  Object.keys(data).forEach(key => {
    formData.append(key, data[key])
  })
  return request({
    url: '/api/v1/mp/meter/importData',
    method: 'post',
    data: formData ,
    ...config,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
