import { request } from '@/api/_service'

// 注：BASE URL 与后台 method 名暂沿用旧项目命名，等待后台数据库路由表统一更新
const BASE = 'production_configuration/matetial_model/matetial_management/'

function apiParams (method, data = {}) {
  return {
    method: `production_configuration_matetial_model_matetial_management_${method}`,
    platform: 'background',
    ...data
  }
}

// 获取全部物料
export function getMaterialMasterAll (data) {
  return request({
    url: BASE + 'all',
    method: 'get',
    params: apiParams('all', data)
  })
}

// 获取物料列表
export function getMaterialMasterList (data) {
  return request({
    url: BASE + 'list',
    method: 'get',
    params: apiParams('list', data)
  })
}

// 创建物料
export function createMaterialMaster (data) {
  return request({
    url: BASE + 'create',
    method: 'post',
    data: apiParams('create', data)
  })
}

// 编辑物料
export function editMaterialMaster (data) {
  return request({
    url: BASE + 'edit',
    method: 'put',
    data: apiParams('edit', data)
  })
}

// 删除物料
export function deleteMaterialMaster (data) {
  return request({
    url: BASE + 'delete',
    method: 'delete',
    data: apiParams('delete', data)
  })
}

// 批量删除物料
export function batchDeleteMaterialMaster (data) {
  return request({
    url: BASE + 'batch_delete',
    method: 'delete',
    data: apiParams('batch_delete', data)
  })
}

// 获取物料数据导入模板
export function getImportTemplate (data) {
  return request({
    url: BASE + 'get_import_template',
    method: 'post',
    responseType: 'blob',
    data: apiParams('get_import_template', data)
  })
}

// 物料数据导入
export function importMaterialData (data) {
  return request({
    url: BASE + 'matetial_data_import',
    method: 'post',
    data: apiParams('matetial_data_import', data)
  })
}

// 物料数据导出任务创建
export function exportMaterialTask (data) {
  return request({
    url: BASE + 'matetial_data_export_task',
    method: 'post',
    data: apiParams('matetial_data_export_task', data)
  })
}
