import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialBomVO, MaterialBomForm, MaterialBomQuery } from '@/api/mes/materialBom/types';

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

export const listMaterialBom = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物料BOM信息详细
 * @param materialBomId
 */
export const getMaterialBom = (materialBomId: string | number): AxiosPromise<MaterialBomVO> => {
  return request({
    url: '/mes/materialBom/' + materialBomId,
    method: 'get'
  });
};

/**
 * 新增物料BOM信息
 * @param data
 */
export const addMaterialBom = (data: MaterialBomForm) => {
  return request({
    url: '/mes/materialBom',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料BOM信息
 * @param data
 */
export const updateMaterialBom = (data: MaterialBomForm) => {
  return request({
    url: '/mes/materialBom',
    method: 'put',
    data: data
  });
};

/**
 * 删除物料BOM信息
 * @param materialBomId
 */
export const delMaterialBom = (materialBomId: string | number | Array<string | number>) => {
  return request({
    url: '/mes/materialBom/' + materialBomId,
    method: 'delete'
  });
};


/**
 * 下拉框查询物料BOM信息列表
 * @param query
 * @returns {*}
 */
export function getMaterialBomList(query) {
  return request({
    url: '/mes/materialBom/getProdMaterialBomList',
    method: 'get',
    params: query
  });
};


/**
 * 新增物料BOM信息
 * @param data
 */
export const addBatchMaterialBom = (data) => {
  return request({
    url: '/mes/materialBom/addBatchMaterialBom',
    method: 'post',
    data: data
  });
};



/**
 * 查询生产bom下拉树结构
 */
export const materialBomTreeSelect = (): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/materialBomTree',
    method: 'get'
  });
};


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

export const listMaterialBomJoinStructure = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/joinStructureList',
    method: 'get',
    params: query
  });
};
