import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialInfoVO, MaterialInfoForm, MaterialInfoId, MaterialInfoIds, MaterialInfoQuery } from '@/api/wcs/materialInfo/types';
import type { WcsDropdownQuery } from '@/api/wcs/types';

/**
 * 查询物料信息列表
 * @param query
 * @returns {*}
 */

export const listMaterialInfo = (query?: MaterialInfoQuery): AxiosPromise<MaterialInfoVO[]> => {
  return request({
    url: '/wcs/materialInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 获取物料信息下拉列表
 * @param query
 */
export const getMaterialInfoList = (query?: WcsDropdownQuery<MaterialInfoQuery>): AxiosPromise<MaterialInfoVO[]> => {
  return request({
    url: '/wcs/materialInfo/getMaterialInfoList',
    method: 'get',
    params: query
  });
};

/**
 * 查询物料信息详细
 * @param objId
 */
export const getMaterialInfo = (objId: MaterialInfoId): AxiosPromise<MaterialInfoVO> => {
  return request({
    url: '/wcs/materialInfo/' + objId,
    method: 'get'
  });
};

/**
 * 批量查询物料信息详细
 * @param ids
 */
export const getMaterialInfoByIds = (ids: MaterialInfoIds): AxiosPromise<MaterialInfoVO[]> => {
  return request({
    url: '/wcs/materialInfo/listByIds',
    method: 'post',
    data: ids
  });
};

/**
 * 统计物料信息数量
 * @param query
 */
export const countMaterialInfo = (query?: MaterialInfoQuery): AxiosPromise<number> => {
  return request({
    url: '/wcs/materialInfo/count',
    method: 'get',
    params: query
  });
};

/**
 * 判断是否存在符合条件的物料信息
 * @param query
 */
export const existsMaterialInfo = (query?: MaterialInfoQuery): AxiosPromise<boolean> => {
  return request({
    url: '/wcs/materialInfo/exists',
    method: 'get',
    params: query
  });
};

/**
 * 新增物料信息
 * @param data
 */
export const addMaterialInfo = (data: MaterialInfoForm) => {
  return request({
    url: '/wcs/materialInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料信息
 * @param data
 */
export const updateMaterialInfo = (data: MaterialInfoForm) => {
  return request({
    url: '/wcs/materialInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除物料信息
 * @param objId
 */
export const delMaterialInfo = (objId: MaterialInfoId | MaterialInfoIds) => {
  return request({
    url: '/wcs/materialInfo/' + objId,
    method: 'delete'
  });
};
