import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrderMainVO, OrderMainForm, OrderMainQuery } from '@/api/order/orderMain/types';

/**
 * 查询订单主信息列表
 * @param query
 * @returns {*}
 */

export const listOrderMain = (query?: OrderMainQuery): AxiosPromise<OrderMainVO[]> => {
  return request({
    url: '/order/orderMain/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询分配订单信息列表
 * @param query
 * @returns {*}
 */

export const listOrderAssignment = (query?: OrderMainQuery): AxiosPromise<OrderMainVO[]> => {
  return request({
    url: '/order/orderMain/assignmentList',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单主信息详细
 * @param id
 */
export const getOrderMain = (id: string | number): AxiosPromise<OrderMainVO> => {
  return request({
    url: '/order/orderMain/' + id,
    method: 'get'
  });
};

/**
 * 新增订单主信息
 * @param data
 */
export const addOrderMain = (data: OrderMainForm) => {
  return request({
    url: '/order/orderMain',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单主信息
 * @param data
 */
export const updateOrderMain = (data: OrderMainForm) => {
  return request({
    url: '/order/orderMain',
    method: 'put',
    data: data
  });
};

/**
 * 删除订单主信息
 * @param id
 */
export const delOrderMain = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/orderMain/' + id,
    method: 'delete'
  });
};

/**
 * 查询数量
 * @param query
 * @returns {*}
 */

export const queryOrderStatusStats = () => {
  return request({
    url: '/order/orderMain/queryOrderStatusStats',
    method: 'get'
  });
};

export function changeCheckStatus(id: string | number, checkStatus: string) {
  const data = {
    id,
    checkStatus
  };
  return request({
    url: '/order/orderMain/checkStatus',
    method: 'put',
    data: data
  });
}
