import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialBomVO, MaterialBomForm, MaterialBomQuery } from '@/api/mes/materialBom/types';
import {BaseMeasurementUnitInfoQuery, BaseMeasurementUnitInfoVO} from "@/api/mes/baseMeasurementUnitInfo/types";
import {MaterialBomVersionQuery, MaterialBomVersionVO} from "@/api/mes/materialBomVersion/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 data
 */
export const deleteMaterialBoms = (data) => {
  return request({
    url: '/mes/materialBom/deleteMaterialBoms',
    method: 'post',
    data: data
  });
};


/**
 * 下拉框查询物料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 = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/materialBomTree',
    method: 'get',
    params:query
  });
};

/**
 * 查询父级生产bom
 */
export const getParentMaterialBom = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/getParentMaterialBom',
    method: 'get',
    params:query
  });
};


/**
 * 查询物料BOM信息列表
 * @param query
 * @returns {*}
 */
export const listMaterialBomJoinStructure = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/materialBom/joinStructureList',
    method: 'get',
    params: query
  });
};


/**
 * 查询单位信息列表
 * @param query
 * @returns {*}
 */

export const getUnitInfoList = (query?: BaseMeasurementUnitInfoQuery): AxiosPromise<BaseMeasurementUnitInfoVO[]> => {
  return request({
    url: '/mes/materialBom/getUnitInfoList',
    method: 'get',
    params: query
  });
};


/**
 * 查询bom版本信息列表
 * @param query
 * @returns {*}
 */

export const getMaterialBomVersionList = (query?: MaterialBomVersionQuery): AxiosPromise<MaterialBomVersionVO[]> => {
  return request({
    url: '/mes/materialBom/getMaterialBomVersionList',
    method: 'get',
    params: query
  });
};

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


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