import request from '@/utils/request'

export function listBatchJob(query) {
  return request({ url: '/warehouse/batch/list', method: 'get', params: query })
}

export function uploadBatchFile(file) {
  const data = new FormData()
  data.append('file', file)
  return request({
    url: '/warehouse/batch/upload',
    method: 'post',
    data,
    headers: { 'Content-Type': 'multipart/form-data', repeatSubmit: false },
    timeout: 60000
  })
}

export function getBatchJob(id) {
  return request({ url: '/warehouse/batch/' + id, method: 'get' })
}

export function listBatchItems(jobId) {
  return request({ url: '/warehouse/batch/' + jobId + '/items', method: 'get' })
}

export function updateBatchItem(data) {
  return request({ url: '/warehouse/batch/item', method: 'put', data })
}

export function updateBatchItemAction(jobId, data) {
  return request({ url: '/warehouse/batch/' + jobId + '/items/action', method: 'put', data })
}

export function deleteBatchItem(id) {
  return request({ url: '/warehouse/batch/item/' + id, method: 'delete' })
}

export function confirmBatchJob(jobId) {
  return request({
    url: '/warehouse/batch/' + jobId + '/confirm',
    method: 'post',
    timeout: 120000,
    headers: { repeatSubmit: false }
  })
}
