import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ZhongcheorderVO, ZhongcheorderForm, ZhongcheorderQuery } from '@/api/order/zhongcheorder/types';

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

export const listZhongcheorder = (query?: ZhongcheorderQuery): AxiosPromise<ZhongcheorderVO[]> => {
  return request({
    url: '/order/zhongcheorder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单列表详细
 * @param id
 */
export const getZhongcheorder = (id: string | number): AxiosPromise<ZhongcheorderVO> => {
  return request({
    url: '/order/zhongcheorder/' + id,
    method: 'get'
  });
};

/**
 * 新增订单列表
 * @param data
 */
export const addZhongcheorder = (data: ZhongcheorderForm) => {
  return request({
    url: '/order/zhongcheorder',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单列表
 * @param data
 */
export const updateZhongcheorder = (data: ZhongcheorderForm) => {
  return request({
    url: '/order/zhongcheorder',
    method: 'put',
    data: data
  });
};

/**
 * 删除订单列表
 * @param id
 */
export const delZhongcheorder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/zhongcheorder/' + id,
    method: 'delete'
  });
};

export const acceptZhongcheorder = (id: string | number): AxiosPromise<string> => {
  return request({
    url: '/order/zhongcheorder/accept',
    method: 'post',
    params: { id }
  });
};

export const rejectZhongcheorder = (id: string | number, reason?: string): AxiosPromise<string> => {
  return request({
    url: '/order/zhongcheorder/reject',
    method: 'post',
    params: { id, reason }
  });
};

export const getZhongcheorderLogistics = (id: string | number): AxiosPromise<any> => {
  return request({
    url: '/order/zhongcheorder/logistics',
    method: 'get',
    params: { id }
  });
};

export const getZhongcheorderLogisticsTrack = (id: string | number): AxiosPromise<any> => {
  return request({
    url: '/order/zhongcheorder/logistics/track',
    method: 'get',
    params: { id }
  });
};

export const settlementZhongcheorder = (id: string | number): AxiosPromise<any> => {
  return request({
    url: '/order/zhongcheorder/settlement',
    method: 'put',
    params: { id }
  });
};

export const setZhongcheorderDeadline = (id: string | number, repaymentDeadline: string): AxiosPromise<any> => {
  return request({
    url: '/order/zhongcheorder/setdeadline',
    method: 'put',
    params: { id, repaymentDeadline }
  });
};

/**
 * 上传发票
 * @param id 订单ID
 * @param invoice 发票文件ID或URL
 */
export const uploadZhongcheorderInvoice = (id: string | number, invoice: string): AxiosPromise<any> => {
  return request({
    url: '/order/zhongcheorder/upload/invoice',
    method: 'put',
    params: { id, invoice }
  });
};
