import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ShipmentPlanVO, ShipmentPlanForm, ShipmentPlanQuery, ShipmentPlanOrderVO } from '@/api/amz/shipmentPlan/types';

/**
 * 查询货件计划列表
 * @param query
 * @returns {*}
 */

export const listShipmentPlan = (query?: ShipmentPlanQuery): AxiosPromise<ShipmentPlanVO[]> => {
  return request({
    url: '/amz/shipmentPlan/list',
    method: 'get',
    params: query
  });
};

export const listShipmentPlanOrder = (query?: ShipmentPlanQuery): AxiosPromise<ShipmentPlanOrderVO[]> => {
  return request({
    url: '/amz/shipmentPlan/list/order',
    method: 'get',
    params: query
  });
};

/**
 * 查询货件计划详细
 * @param id
 */
export const getShipmentPlan = (id: string | number): AxiosPromise<ShipmentPlanVO> => {
  return request({
    url: '/amz/shipmentPlan/' + id,
    method: 'get'
  });
};

/**
 * 获取今天的货件计划数据
 * @param id
 */
export const takeTodayAmzPlanData = () => {
  return request({
    url: '/amz/shipmentPlan/take-today-amz-plan-data',
    method: 'get'
  });
};

/**
 * 查询货件计划详细
 * @param id
 */
export const getQuote = (id: string | number): AxiosPromise<ShipmentPlanVO> => {
  return request({
    url: '/amz/shipmentPlan/quote' + id,
    method: 'get'
  });
};

/**
 * 新增货件计划
 * @param data
 */
export const addShipmentPlan = (data: ShipmentPlanForm) => {
  return request({
    url: '/amz/shipmentPlan',
    method: 'post',
    data: data
  });
};

/**
 * 修改货件计划
 * @param data
 */
export const updateShipmentPlan = (data: ShipmentPlanForm) => {
  return request({
    url: '/amz/shipmentPlan',
    method: 'put',
    data: data
  });
};

export const linkShipmentPlan = (data: ShipmentPlanForm) => {
  return request({
    url: '/amz/shipmentPlan/link',
    method: 'put',
    data: data
  });
};

export const createBatchRelations = (data: any) => {
  return request({
    url: '/amz/sendShipmentRel/createBatchRelations',
    method: 'post',
    data: data
  });
};

export const updateShipmentPlanList = (data: string[]) => {
  return request({
    url: '/amz/shipmentPlan/update/list/send',
    method: 'post',
    data: data
  });
};

/**
 * 删除货件计划
 * @param id
 */
export const delShipmentPlan = (id: string | number | Array<string | number>) => {
  return request({
    url: '/amz/shipmentPlan/' + id,
    method: 'delete'
  });
};

export const deleteShipmentPlanSendOrder = (shipmentPlanId: string | number, sendOrderId: string | number) => {
  return request({
    url: '/amz/shipmentPlan/delete/' + shipmentPlanId + '/' + sendOrderId,
    method: 'delete'
  });
};
