import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SubOrderVO, SubOrderQuery, SubOrderDispatchQuery } from './types';

/**
 * 派单中心查询子订单列表
 */
export const listSubOrderOnDispatch = (query?: SubOrderDispatchQuery): AxiosPromise<SubOrderVO[]> => {
    return request({
        url: '/order/subOrder/listOnDispatch',
        method: 'get',
        params: query
    });
};

/**
 * 查询子订单列表
 * @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; price: 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
    });
};
