import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OutstockOrderVO, OutstockOrderForm, OutstockOrderQuery } from '@/api/wms/outstockOrder/types';


/**
 * 查询出库单列表
 * @param query
 * @returns {*}
 */

export const listOutstockOrder = (query?: OutstockOrderQuery): AxiosPromise<OutstockOrderVO[]> => {
  return request({
    url: '/wms/outstockOrder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询出库单详细
 * @param outstockId
 */
export const getOutstockOrder = (outstockId: string | number): AxiosPromise<OutstockOrderVO> => {
  return request({
    url: '/wms/outstockOrder/' + outstockId,
    method: 'get'
  });
};

/**
 * 新增出库单
 * @param data
 */
export const addOutstockOrder = (data: OutstockOrderForm) => {
  return request({
    url: '/wms/outstockOrder',
    method: 'post',
    data: data
  });
};

/**
 * 修改出库单
 * @param data
 */
export const updateOutstockOrder = (data: OutstockOrderForm) => {
  return request({
    url: '/wms/outstockOrder',
    method: 'put',
    data: data
  });
};

/**
 * 删除出库单
 * @param outstockId
 */
export const delOutstockOrder = (outstockId: string | number | Array<string | number>) => {
  return request({
    url: '/wms/outstockOrder/' + outstockId,
    method: 'delete'
  });
};

/**
 * 审批出库单：更新审核状态/意见（后端自动填写审核时间）
 * @param data 需包含 outstockId, auditStatus(0/1/2), auditComments
 */
export const approveOutstockOrder = (data: Partial<OutstockOrderForm>) => {
  return request({
    url: '/wms/outstockOrder/approve',
    method: 'put',
    data: data
  });
};

/**
 * 查询出库单列表
 * @param query
 * @returns {*}
 */

export const getOutstockOrderList = (query?: OutstockOrderQuery): AxiosPromise<OutstockOrderVO[]> => {
  return request({
    url: '/wms/outstockOrder/getOutstockOrderList',
    method: 'get',
    params: query
  });
};
