import request from '@/utils/request'
import { postForm } from '@/utils/legacyRequest'

const headers = { isToken: false }

export function listMaterial(query) {
  return postForm('/risk/material/list', query, { headers })
}

export function getMaterial(materialId) {
  return request({
    url: '/risk/material/' + materialId,
    method: 'get',
    headers
  })
}

export function addMaterial(data) {
  return postForm('/risk/material/add', data, { headers })
}

export function updateMaterial(data) {
  return postForm('/risk/material/edit', data, { headers })
}

export function delMaterial(materialId) {
  return postForm('/risk/material/remove', { ids: materialId }, { headers })
}

export function uploadMaterialFile(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/common/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
