import type { UserProfile } from '@/types/mall-types.uts'

export type DeliveryOnlineStatus = 'online' | 'resting' | 'busy'

export type DeliveryAccountStatus = 'active' | 'disabled' | 'locked' | 'suspended'

export type DeliveryCertificateStatus = 'valid' | 'expired' | 'pending'

export type DeliveryOrderStatus =
	'pending_assignment' |
	'pending_accept' |
	'accepted' |
	'waiting_departure' |
	'departed' |
	'on_the_way' |
	'arrived' |
	'checked_in' |
	'in_service' |
	'serving' |
	'pending_confirm' |
	'pending_submit' |
	'pending_acceptance' |
	'completed' |
	'rejected' |
	'abnormal' |
	'terminated' |
	'exception_pending' |
	'cancelled' |
	'settled' |
	'archived'

export type DeliveryExceptionType =
	'cannot_contact_user' |
	'user_not_home' |
	'family_uncooperative' |
	'outside_service_scope' |
	'staff_cannot_continue' |
	'complaint_dispute' |
	'cannot_contact_elder' |
	'cannot_enter_home' |
	'wrong_address' |
	'elder_refuse_service' |
	'family_requests_reschedule' |
	'safety_risk' |
	'elder_health_abnormal' |
	'emergency_illness' |
	'item_unavailable' |
	'other'

export type DeliveryLocationType = {
	latitude: number
	longitude: number
	address: string
	time: string
}

export type DeliveryTimelineItemType = {
	id: string
	title: string
	time: string
	description: string
}

export type DeliveryStatusLogType = {
	id: string
	orderId: string
	fromStatus: DeliveryOrderStatus
	toStatus: DeliveryOrderStatus
	operatorRole: string
	operatorId: string
	remark: string
	createdAt: string
}

export type DeliveryServiceItemType = {
	id: string
	name: string
	required: boolean
	completed: boolean
	incompleteReason: string
	remark: string
	updatedAt: string
}

export type DeliveryEvidenceRecordType = {
	id: string
	orderId: string
	phase: string
	fileType: string
	name: string
	url: string
	localPath: string
	status: string
	progress: number
	retryable: boolean
	createdAt: string
}

export type DeliveryHealthMetricsType = {
	bloodPressure: string
	heartRate: string
	bloodSugar: string
	bloodOxygen: string
}

export type DeliveryConfirmationType = {
	method: 'sms_code' | 'signature' | 'none'
	code: string
	signatureName: string
	signatureUrl: string
	confirmedAt: string
}

export type DeliveryServiceRecordType = {
	id: string
	orderId: string
	startTime: string
	endTime: string
	actualDurationMinutes: number
	serviceItems: Array<DeliveryServiceItemType>
	serviceContent: Array<string>
	processNote: string
	elderStatus: string
	healthMetrics: DeliveryHealthMetricsType
	materialsUsed: string
	abnormalNote: string
	photos: Array<string>
	staffRemark: string
	familyConfirmation: DeliveryConfirmationType
	createdAt: string
	updatedAt: string
}

export type DeliveryAbnormalReportType = {
	id: string
	orderId: string
	type: DeliveryExceptionType
	description: string
	occurredAt: string
	locationText: string
	images: Array<string>
	needPlatformIntervention: boolean
	requestCancelOrder: boolean
	requestReschedule: boolean
	createdAt: string
}

export type DeliveryOrderType = {
	id: string
	orderNo: string
	serviceType: string
	serviceName: string
	serviceCategory: string
	serviceItems: Array<DeliveryServiceItemType>
	serviceContentOptions?: Array<string>
	elderId: string
	elderName: string
	elderNameMasked: string
	elderGender: string
	elderAge: number
	elderPhone: string
	elderPhoneMasked: string
	fullElderName: string
	fullPhone: string
	contactRelation: string
	addressSummary: string
	address: string
	addressDetail: string
	fullAddress: string
	latitude: number
	longitude: number
	appointmentTime: string
	appointmentStartTime: string
	appointmentEndTime: string
	duration: number
	estimatedDuration: number
	price: number
	staffIncome: number
	distance: string
	actualStartTime: string
	actualEndTime: string
	status: DeliveryOrderStatus
	statusText: string
	statusTone: string
	riskTags: Array<string>
	healthTags: Array<string>
	careLevel: string
	needFamilyPresent: boolean
	needMaterials: boolean
	remark: string
	merchantId: string
	merchantName: string
	deliveryStaffId: string
	deliveryStaffName: string
	acceptTime: string
	rejectTime?: string
	departTime: string
	arriveTime: string
	checkinTime: string
	startServiceTime?: string
	finishTime: string
	cancelReason: string
	exceptionType: string
	exceptionDesc: string
	evidenceList: Array<DeliveryEvidenceRecordType>
	signatureUrl: string
	signatureName: string
	satisfactionStatus: string
	settlementStatus: string
	archiveStatus: string
	createdAt: string
	updatedAt: string
	contactName: string
	contactPhone: string
	notices: Array<string>
	timeline: Array<DeliveryTimelineItemType>
	statusLog: Array<DeliveryStatusLogType>
	serviceSummary: string
	progressNote: string
	distanceKm: string
	allowCheckinRadiusMeters: number
	lastLocation: DeliveryLocationType | null
	trackPoints: Array<DeliveryLocationType>
	serviceRecord: DeliveryServiceRecordType | null
	abnormalReport: DeliveryAbnormalReportType | null
}

export type DeliveryCertificateType = {
	id: string
	name: string
	status: DeliveryCertificateStatus
	expireAt: string
	issuer: string
	imageUrl: string
}

export type DeliveryInfoType = {
	id: string
	userId: string
	staffNo: string
	name: string
	phone: string
	role: string
	status: DeliveryAccountStatus
	organizationId: string
	organizationName: string
	certificates: Array<DeliveryCertificateType>
	certificateStatus: DeliveryCertificateStatus
	certificateExpireAt: string
	onlineStatus: DeliveryOnlineStatus
	serviceArea: string
	skills: Array<string>
	avatarUrl: string
	todayAccepted: number
	todayServing: number
	todayCompleted: number
	usesMock: boolean
}

export type DeliveryDashboardType = {
	pendingAssignmentCount: number
	pendingAcceptCount: number
	todayOrderCount: number
	pendingDepartCount: number
	servingCount: number
	completedCount: number
	exceptionCount: number
	expectedIncome: number
	onlineStatus: DeliveryOnlineStatus
	nextOrder: DeliveryOrderType | null
	recentOrders: Array<DeliveryOrderType>
}

export type DeliveryMessageType = {
	id: string
	title: string
	content: string
	type: string
	createdAt: string
	read: boolean
	orderId: string
}

export type DeliveryRecordType = {
	id: string
	orderId: string
	orderNo: string
	serviceName: string
	elderName: string
	elderNameMasked: string
	status: string
	statusText: string
	appointmentStartTime: string
	appointmentTime: string
	actualStartTime: string
	actualEndTime: string
	staffIncome: number
	settlementStatus: string
	acceptanceStatus: string
	exceptionDesc: string
	ratingText: string
	hasServiceRecord: boolean
}

export type DeliveryLoginPayloadType = {
	account: string
	password: string
}

export type DeliveryLoginResultType = {
	token: string
	userInfo: UserProfile
	deliveryInfo: DeliveryInfoType | null
	usesMock: boolean
}

export type DeliveryOrderQueryType = {
	tab: string
	keyword: string
}

export type DeliveryProgressPayloadType = {
	items: Array<DeliveryServiceItemType>
	progressNote: string
	serviceSummary: string
}

export type DeliveryCheckinPayloadType = {
	location: DeliveryLocationType
	note: string
	photos: Array<string>
	checkinMode: string
}

export type DeliveryFinishPayloadType = {
	serviceSummary: string
	signatureName: string
	confirmByFamily: boolean
}

export type DeliveryExceptionPayloadType = {
	exceptionType: DeliveryExceptionType
	description: string
	images: Array<string>
	occurredAt?: string
	locationText?: string
	needPlatformIntervention?: boolean
	requestCancelOrder?: boolean
	requestReschedule?: boolean
}