import axiosInstance from "@/api/axios.ts";
import type {IConveyTaskQuery} from "@/interface/page/convey/IConveyTaskQuery.ts";
import type {IAppConveyTask} from "@/model/table/IAppConveyTask.ts";
import type {IConveyTaskReportReq} from "@/interface/page/convey/IConveyTaskReportReq.ts";

export default class ConveyTaskApi {

    // 分页查询
    static query(query: IConveyTaskQuery, pageSize: number, pageIndex: number): Promise<any> {
        return axiosInstance.post('/app/conveyTask/queryConveyTask', query,{
            params: {
                pageSize: pageSize,
                pageIndex: pageIndex
            }
        });
    };

    // 分页查询
    static queryBak(query: IConveyTaskQuery, pageSize: number, pageIndex: number): Promise<any> {
        return axiosInstance.post('/app/conveyTask/queryConveyTaskBak', query,{
            params: {
                pageSize: pageSize,
                pageIndex: pageIndex
            }
        });
    };

    // 新增
    static add(data: IAppConveyTask): Promise<any> {
        return axiosInstance.post('/app/conveyTask/addConveyTask', data);
    };

    // 修改状态
    static updateStatus(taskId: string, taskStatus: number | undefined): Promise<any> {
        return axiosInstance.put('/app/conveyTask/updateConveyTaskStatus', null, {
            params: {
                taskId: taskId,
                taskStatus: taskStatus
            }
        });
    };

    // 完成任务
    static complete(taskId: string | undefined, arriveLocation: string | undefined): Promise<any> {
        return axiosInstance.put('/app/conveyTask/completeConveyTask', null, {
            params: {
                taskId: taskId,
                arriveLocation: arriveLocation
            }
        });
    };

    // 取消任务
    static cancel(taskId: string | undefined): Promise<any> {
        return axiosInstance.delete('/app/conveyTask/cancelConveyTask', {
            params: {
                taskId: taskId
            }
        });
    };

    // 上报任务完成
    static reportComplete(taskReportData: IConveyTaskReportReq): Promise<any> {
        return axiosInstance.post('/app/conveyTask/reporterConveyTaskComplete', taskReportData);
    };

    // 上报任务取消
    static reportCancel(taskReportData: IConveyTaskReportReq): Promise<any> {
        return axiosInstance.post('/app/conveyTask/reporterConveyTaskCancel', taskReportData);
    };

    // 上报任务完成 ---- 备份表
    static reportBakComplete(taskReportData: IConveyTaskReportReq): Promise<any> {
        return axiosInstance.post('/app/conveyTask/reporterConveyTaskBakComplete', taskReportData);
    };

    // 上报任务取消 ---- 备份表
    static reportBakCancel(taskReportData: IConveyTaskReportReq): Promise<any> {
        return axiosInstance.post('/app/conveyTask/reporterConveyTaskBakCancel', taskReportData);
    };

    // 导出备份表
    static exportBak(query: IConveyTaskQuery): Promise<any> {
        return axiosInstance.post('/app/conveyTask/exportConveyTaskBak', query, {
            responseType: 'blob',
            timeout: 30000
        });
    }
}