import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PlanInfoVO, PlanInfoForm, PlanInfoQuery } from '@/api/mes/planInfo/types';
import {MaterialBomQuery, MaterialBomVO} from "@/api/mes/materialBom/types";

/**
 * 查询生产工单信息列表
 * @param query
 * @returns {*}
 */

export const listPlanInfo = (query?: PlanInfoQuery): AxiosPromise<PlanInfoVO[]> => {
  return request({
    url: '/mes/planInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询生产工单信息详细
 * @param planId
 */
export const getPlanInfo = (planId: string | number): AxiosPromise<PlanInfoVO> => {
  return request({
    url: '/mes/planInfo/' + planId,
    method: 'get'
  });
};

/**
 * 新增生产工单信息
 * @param data
 */
export const addPlanInfo = (data: PlanInfoForm) => {
  return request({
    url: '/mes/planInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改生产工单信息
 * @param data
 */
export const updatePlanInfo = (data: PlanInfoForm) => {
  return request({
    url: '/mes/planInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除生产工单信息
 * @param planId
 */
export const delPlanInfo = (planId: string | number | Array<string | number>) => {
  return request({
    url: '/mes/planInfo/' + planId,
    method: 'delete'
  });
};


/**
 * 下拉框查询生产工单信息列表
 * @param query
 * @returns {*}
 */
export function getPlanInfoList (query) {
    return request({
        url: '/mes/planInfo/getPlanInfoList',
        method: 'get',
        params: query
    });
};

// 获取工艺路线的所有工艺步骤
export function getBaseRouteProcesses(query) {
  return request({
    url: '/mes/planInfo/getBaseRouteProcesses' ,
    method: 'get',
    params: query
  })
}

// 获取派工编号
export function getDispatchCode() {
  return request({
    url: '/mes/planInfo/getDispatchCode',
    method: 'get'
  })
}
// 查询生产派工列表
export function selectProductPlans(query) {
  return request({
    url: '/mes/planInfo/selectProductPlans',
    method: 'get',
    params: query
  })
}

// 生产工单新增生产派工List
export function orderAddProductPlanList(data) {
  return request({
    url: '/mes/planInfo/orderAddProductPlanList',
    method: 'post',
    data: data
  })
}

/**
 * 下发选中计划
 * @param planId
 */
export const issuePlanInfo = (workshopId: string | number, planId: string | number | Array<string | number>) => {
  return request({
    url: '/mes/planInfo/issuePlanInfo/' + workshopId + "/" + planId,
    method: 'get'
  });
};

/**
 * 查询生产工单信息列表
 * @param query
 * @returns {*}
 */

export const queryMoritorList = (query?: PlanInfoQuery): AxiosPromise<PlanInfoVO[]> => {
  return request({
    url: '/mes/planInfo/queryMoritorList',
    method: 'get',
    params: query
  });
};


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


/**
 * 查询物料bom版本下拉树结构
 */
export const materialBomVersionSelect = (query?: MaterialBomQuery): AxiosPromise<MaterialBomVO[]> => {
  return request({
    url: '/mes/planInfo/materialBomVersionSelect',
    method: 'get',
    params:query
  });
};

