import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SubOrderVO, SubOrderQuery, SubOrderListParams, SubOrderListResult, SubOrderHistoryVO, SubOrderPetVO, SubOrderStoreVO } from './types';

/**
 * 查询子订单列表
 * @param query
 * @returns {*}
 */
export const listSubOrder = (query?: SubOrderQuery): AxiosPromise<{ total: number, rows: SubOrderVO[] }> => {
    return request({
        url: '/order/subOrder/list',
        method: 'get',
        params: query
    });
};

export const dispatchSubOrder = (data: { orderId: string | number; fulfiller: string | number; fulfillmentCommission: number; }) => {
    return request({
        url: '/order/subOrder/dispatch',
        method: 'put',
        data
    });
};

export const getSubOrderInfo = (id: string | number): AxiosPromise<SubOrderVO> => {
    return request({
        url: '/order/subOrder/getInfo',
        method: 'get',
        params: { id }
    });
};

export const cancelSubOrder = (data: { orderId: string | number; }) => {
    return request({
        url: '/order/subOrder/cancel',
        method: 'put',
        data
    });
};

export const remarkSubOrder = (data: { orderId: string | number; remark: string; }) => {
    return request({
        url: '/order/subOrder/remark',
        method: 'put',
        data
    });
};

export const confirmSubOrder = (data: { id: string | number; }) => {
    return request({
        url: '/order/subOrder/confirm',
        method: 'put',
        data
    });
};

export const nursingSummarySubOrder = (data: { orderId: string | number; content: string; }) => {
    return request({
        url: '/order/subOrder/nursingSummary',
        method: 'put',
        data
    });
};

/**
 * 根据客户ID查询子订单列表
 * @param customerId 
 * @returns 
 */
export const listSubOrderOnCustomer = (customerId: string | number): AxiosPromise<SubOrderHistoryVO[]> => {
    return request({
        url: '/order/subOrder/listOnCustomer',
        method: 'get',
        params: { customerId }
    });
};

/**
 * 根据宠物ID查询子订单列表
 */
export const listSubOrderOnPet = (petId: string | number): AxiosPromise<SubOrderPetVO[]> => {
    return request({
        url: '/order/subOrder/listOnPet',
        method: 'get',
        params: { petId }
    });
};

/**
 * 根据门店查询服务订单记录
 */
export const listSubOrderOnStore = (params: { storeId: string | number; pageNum: number; pageSize: number; }): AxiosPromise<{ total: number, rows: SubOrderStoreVO[] }> => {
    return request({
        url: '/order/subOrder/listOnStore',
        method: 'get',
        params
    });
};

/**
 * 导出订单列表为 Excel
 * @param data 查询参数
 */
export const exportSubOrder = (data: { status?: number; service?: number; content?: string }) => {
  return request({
    url: '/order/subOrder/export',
    method: 'post',
    data,
    responseType: 'blob'
  });
};
