import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialInfoVO, MaterialInfoForm, MaterialInfoQuery } from '@/api/oa/base/materialInfo/types';
import { RelationMaterialVO } from '@/api/oa/base/relationMaterial/types';

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

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

/**
 * 查询SAP物料信息详细
 * @param materialId
 */
export const getMaterialInfo = (materialId: string | number): AxiosPromise<MaterialInfoVO> => {
  return request({
    url: '/oa/base/materialInfo/' + materialId,
    method: 'get'
  });
};

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

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

/**
 * 删除SAP物料信息
 * @param materialId
 */
export const delMaterialInfo = (materialId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/base/materialInfo/' + materialId,
    method: 'delete'
  });
};

/**
 * 下拉框查询SAP物料信息列表
 * @param query
 * @returns {*}
 */
export function getBaseMaterialInfoList (query) {
    return request({
        url: '/oa/base/materialInfo/getBaseMaterialInfoList',
        method: 'get',
        params: query
    });
};

/**
 * 查询物料信息并关联销售物料表
 * @param query
 * @returns {*}
 */
export const listMaterialInfoWithRelation = (query?: MaterialInfoQuery): AxiosPromise<RelationMaterialVO[]> => {
  return request({
    url: '/oa/base/materialInfo/listWithRelation',
    method: 'get',
    params: query
  });
};

/**
 * 合同新增SAP物料信息
 * @param data
 */
export const contractAddMaterialInfo = (data: MaterialInfoForm) => {
  return request({
    url: '/oa/base/materialInfo/contractAdd',
    method: 'post',
    data: data
  });
};
