import { acceptDeliveryOrderById, arriveOrderById, checkinOrderById, finishServiceById, getDeliveryDashboardByStaffId, getDeliveryMessagesList, getDeliveryOrderDetailById, getDeliveryOrdersByStaffId, getDeliveryProfileByUserId, getDeliveryRecordsByStaffId, loginDelivery as loginDeliveryApi, rejectDeliveryOrderById, retryEvidenceById, saveServiceProgressById, startDepartById, startServiceById, submitExceptionById, updateDeliveryOnlineStatusByStaffId, uploadEvidenceById } from '@/api/delivery.uts' import { getDeliveryInfo, getUserInfo, requireDeliveryAuth } from '@/utils/deliveryAuth.uts' import type { DeliveryCheckinPayloadType, DeliveryDashboardType, DeliveryExceptionPayloadType, DeliveryFinishPayloadType, DeliveryInfoType, DeliveryLocationType, DeliveryLoginPayloadType, DeliveryLoginResultType, DeliveryMessageType, DeliveryOrderQueryType, DeliveryOrderType, DeliveryProgressPayloadType, DeliveryRecordType, DeliveryEvidenceRecordType } from '@/types/delivery.uts' function getCurrentStaffId(): string { const info = getDeliveryInfo() if (info != null) { return info.id } return '' } export async function loginDelivery(payload: DeliveryLoginPayloadType): Promise { return await loginDeliveryApi(payload) } export async function getDeliveryProfile(): Promise { const userInfo = getUserInfo() if (userInfo == null || userInfo.id == null || userInfo.id == '') { return null } return await getDeliveryProfileByUserId(userInfo.id) } export async function getDeliveryByUserId(userId: string): Promise { return await getDeliveryProfileByUserId(userId) } export async function getCurrentDeliverer(): Promise { return await getDeliveryProfile() } export async function checkDeliveryAccountByUserId(userId: string): Promise { return await getDeliveryProfileByUserId(userId) } export async function checkDeliveryAuth(): Promise { const result = await requireDeliveryAuth({ redirectOnFail: false, toastOnFail: false }) return result.ok } export async function getDeliveryDashboard(): Promise { return await getDeliveryDashboardByStaffId(getCurrentStaffId()) } export async function getDeliveryOrders(params: DeliveryOrderQueryType): Promise> { return await getDeliveryOrdersByStaffId(getCurrentStaffId(), params) } export async function getDeliveryOrderDetail(id: string): Promise { return await getDeliveryOrderDetailById(id) } export async function acceptDeliveryOrder(id: string): Promise { return await acceptDeliveryOrderById(id) } export async function rejectDeliveryOrder(id: string, reason: string): Promise { return await rejectDeliveryOrderById(id, reason) } export async function startDepart(id: string, location: DeliveryLocationType): Promise { return await startDepartById(id, location) } export async function arriveOrder(id: string, location: DeliveryLocationType): Promise { return await arriveOrderById(id, location) } export async function checkinOrder(id: string, payload: DeliveryCheckinPayloadType): Promise { return await checkinOrderById(id, payload) } export async function startService(id: string): Promise { return await startServiceById(id) } export async function saveServiceProgress(id: string, payload: DeliveryProgressPayloadType): Promise { return await saveServiceProgressById(id, payload) } export async function uploadEvidence(id: string, phase: string, files: Array): Promise> { return await uploadEvidenceById(id, phase, files) } export async function retryUploadEvidence(id: string, evidenceId: string): Promise { return await retryEvidenceById(id, evidenceId) } export async function submitException(id: string, payload: DeliveryExceptionPayloadType): Promise { return await submitExceptionById(id, payload) } export async function finishService(id: string, payload: DeliveryFinishPayloadType): Promise { return await finishServiceById(id, payload) } export async function getDeliveryRecords(): Promise> { return await getDeliveryRecordsByStaffId(getCurrentStaffId()) } export async function getDeliveryMessages(): Promise> { return await getDeliveryMessagesList() } export async function updateDeliveryOnlineStatus(status: string): Promise { return await updateDeliveryOnlineStatusByStaffId(getCurrentStaffId(), status) }