import {
  AddMaterialParams,
  BaseListResult,
  BaseResult,
  EditMaterialParams,
  GetMatterListparams,
  MaterialListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/materialClass';

/** 新增物料类别 */
export function addMaterial(data: AddMaterialParams): BaseResult {
  return request({
    method: 'POST',
    url: `${BASE_URL}/addMaterialClass`,
    data,
  });
}

/** 修改物料类别 */
export function editMaterial(data: EditMaterialParams): BaseResult {
  return request({
    method: 'PUT',
    url: `${BASE_URL}/updateMaterialClass`,
    data,
  });
}

/** 获取列表 */
export function getMaterialList(
  data: GetMatterListparams,
  signal?: AbortSignal,
): BaseListResult<MaterialListData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getMaterialClass`,
    signal,
  });
}

/** 获取详情 */
export function getMaterialInfo(id: string): BaseListResult<MaterialListData> {
  return request({
    method: 'GET',
    data: {id, page: '1', limit: '1'},
    url: `${BASE_URL}/getMaterialClass`,
  });
}

/** 删除列表 */
export function deleteMaterial(id: string): BaseResult {
  return request({
    method: 'DELETE',
    data: {id},
    url: `${BASE_URL}/delMaterialClass`,
  });
}

/** 导出 */
export function exportMatter(data: GetMatterListparams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/Export`,
    skipError: true,
  });
}
