import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PurchaseOrderVO, PurchaseOrderForm, PurchaseOrderQuery } from '@/api/amz/purchaseOrder/types';

/**
 * 查询采购单主列表
 * @param query
 * @returns {*}
 */

export const listPurchaseOrder = (query?: PurchaseOrderQuery): AxiosPromise<PurchaseOrderVO[]> => {
  return request({
    url: '/amz/purchaseOrder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询采购单主详细
 * @param orderSn
 */
export const getPurchaseOrder = (orderSn: string | number): AxiosPromise<PurchaseOrderVO> => {
  return request({
    url: '/amz/purchaseOrder/' + orderSn,
    method: 'get'
  });
};

/**
 * 新增采购单主
 * @param data
 */
export const addPurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/amz/purchaseOrder',
    method: 'post',
    data: data
  });
};

/**
 * 修改采购单主
 * @param data
 */
export const updatePurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/amz/purchaseOrder',
    method: 'put',
    data: data
  });
};

/**
 * 确认采购订单
 * @param data
 */
export const confirmPurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/amz/purchaseOrder/confirm',
    method: 'post',
    data: data
  });
};

/**
 * 删除采购单主
 * @param orderSn
 */
export const delPurchaseOrder = (orderSn: string | number | Array<string | number>) => {
  return request({
    url: '/amz/purchaseOrder/' + orderSn,
    method: 'delete'
  });
};

export const takeTodayPurchaseOrder = () => {
  return request({
    url: '/amz/purchaseOrder/take-today-purchase-order',
    method: 'get'
  });
};

export const updateTodayPurchaseOrder = () => {
  return request({
    url: '/amz/purchaseOrder/update-today-purchase-order',
    method: 'get'
  });
};
