import request from '@/utils/request'

// 查询安全库存列表
export function listSafetyStock(query) {
  return request({
    url: '/system/safetyStock/list',
    method: 'get',
    params: query
  })
}

// 查询安全库存详细
export function getSafetyStock(id) {
  return request({
    url: '/system/safetyStock/' + id,
    method: 'get'
  })
}

// 新增安全库存
export function addSafetyStock(data) {
  return request({
    url: '/system/safetyStock',
    method: 'post',
    data: data
  })
}

// 修改安全库存
export function updateSafetyStock(data) {
  return request({
    url: '/system/safetyStock',
    method: 'put',
    data: data
  })
}

// 删除安全库存
export function delSafetyStock(id) {
  const ids = Array.isArray(id) ? id.join(',') : id
  // 优先尝试 REST 风格 DELETE，不支持则回退到 POST /remove
  return request({
    url: '/system/safetyStock/' + ids,
    method: 'delete'
  }).catch(() => {
    return request({
      url: '/system/safetyStock/remove',
      method: 'post',
      data: { ids }
    })
  })
}
