import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WmsShippingArrivalConfirmForm, WmsShippingBillForm, WmsShippingBillQuery, WmsShippingBillVO } from '@/api/wms/wmsShippingBill/types';

/**
 * 查询发货单列表
 * @param query
 * @returns {*}
 */

export const listWmsShippingBill = (query?: WmsShippingBillQuery): AxiosPromise<WmsShippingBillVO[]> => {
  return request({
    url: '/wms/wmsShippingBill/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询发货单详细
 * @param shippingBillId
 */
export const getWmsShippingBill = (shippingBillId: string | number): AxiosPromise<WmsShippingBillVO> => {
  return request({
    url: '/wms/wmsShippingBill/' + shippingBillId,
    method: 'get'
  });
};

/**
 * 新增发货单
 * @param data
 */
export const addWmsShippingBill = (data: WmsShippingBillForm) => {
  return request({
    url: '/wms/wmsShippingBill',
    method: 'post',
    data: data
  });
};

/**
 * 修改发货单
 * @param data
 */
export const updateWmsShippingBill = (data: WmsShippingBillForm) => {
  return request({
    url: '/wms/wmsShippingBill',
    method: 'put',
    data: data
  });
};

/**
 * 删除发货单
 * @param shippingBillId
 */
export const delWmsShippingBill = (shippingBillId: string | number | Array<string | number>) => {
  return request({
    url: '/wms/wmsShippingBill/' + shippingBillId,
    method: 'delete'
  });
};

/**
 * 下拉框查询发货单列表
 * @param query
 * @returns {*}
 */
export function getWmsShippingBillList(query) {
  return request({
    url: '/wms/wmsShippingBill/getWmsShippingBillList',
    method: 'get',
    params: query
  });
}

/**
 * 提交发货单并发起审批流程
 * @param data
 */
export const shippingBillSubmitAndFlowStart = (data: WmsShippingBillForm): AxiosPromise<WmsShippingBillVO> => {
  return request({
    url: '/wms/wmsShippingBill/shippingBillSubmitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 导出发货单Word文档
 * @param shippingBillId 发货单ID
 */
export const exportShippingBillWord = (shippingBillId: string | number) => {
  return request({
    url: '/wms/wmsShippingBill/exportWord/' + shippingBillId,
    method: 'get',
    responseType: 'blob'
  });
};

/**
 * 到货确认：保存到货信息并更新发货状态
 * @param data 到货确认入参
 */
export const arrivalConfirmShippingBill = (data: WmsShippingArrivalConfirmForm): AxiosPromise<WmsShippingBillVO> => {
  return request({
    url: '/wms/wmsShippingBill/arrivalConfirm',
    method: 'post',
    data: data
  });
};
