/**
 * 工作台详情接口
 */
import { request } from '../../utils/request'
import type { acceptOrderInfo, acceptOrderInfo2 } from '../../types/order'

/**
 * 根据 ID 获取维保工单详情
 * @param id 工单 ID
 */
export const getOrderInfoById = (id: string): Promise<any> => {
    return request({
        url: `/mobile/order/${id}`,
        method: 'GET'
    })
}

/**
 * 根据 ID 获取维修工单详情
 * @param id 工单 ID
 */
export const getRepairOrderInfoById = (id: string): Promise<any> => {
    return request({
        url: `/mobile/order/repairOrder/${id}`,
        method: 'GET'
    })
}

// 接单（支持一次性选择处理人员和工作班成员）
export const acceptOrder = (gxtWorkOrder: acceptOrderInfo2 | null): Promise<any> => {
	const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/accept`,
		method: 'PUT',
		data: data
	})
}

// 挂起
export const suspendOrder = (gxtWorkOrder: acceptOrderInfo | null): Promise<any> => {
	const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/suspend`,
		method: 'PUT',
		data: data
	})
}

// 审批
export const approveOrder = (gxtWorkOrder: acceptOrderInfo2 | null): Promise<any> => {
	const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/approve`,
		method: 'PUT',
		data: data
	})
}

//
export const resumeOrder = (gxtWorkOrder: acceptOrderInfo | null): Promise<any> => {
	const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/resume`,
		method: 'PUT',
		data: data
	})
}

export const returnRepairOrder = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	// const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	// const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/returnRepairOrder`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}

export const resetAndStart = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	// const plainObject = gxtWorkOrder != null ? JSON.parse(JSON.stringify(gxtWorkOrder)) : null;
	// const data: UTSJSONObject | null = plainObject as UTSJSONObject;
	return request({
		url: `/mobile/order/resetAndStart`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}

// 维保工单结单
export const finishOrder = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	return request({
		url: `/mobile/order/finish`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}

// 维修工单结单
export const repairFinishOrder = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	return request({
		url: `/mobile/order/repairFinish`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}

// 维保工单停机
export const shutdownOrder = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	return request({
		url: `/mobile/order/shutdown`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}

// 复运
export const restartOrder = (gxtWorkOrder: UTSJSONObject | null): Promise<any> => {
	return request({
		url: `/mobile/order/restart`,
		method: 'PUT',
		data: gxtWorkOrder
	})
}
