import { StressLevel } from '@/utils/stress'; import { notificationService, NotificationData, NotificationTypes } from './notifications'; interface HRVStressNotificationPayload { hrvValue: number; stressIndex: number; stressLevel: StressLevel; recordedAt: string; interpretation: string; recommendations: string[]; dataSource: string; message?: string; } const LEVEL_CONFIG: Record< StressLevel, { emoji: string; title: string; priority: NotificationData['priority']; } > = { low: { emoji: '🧘', title: '状态放松', priority: 'normal', }, moderate: { emoji: '🙂', title: '压力适中', priority: 'normal', }, high: { emoji: '⚠️', title: '压力偏高', priority: 'high', }, }; export async function sendHRVStressNotification( payload: HRVStressNotificationPayload ): Promise { const config = LEVEL_CONFIG[payload.stressLevel]; const recommendation = payload.recommendations[0]; const lines = [ `HRV ${payload.hrvValue}ms · 压力指数 ${payload.stressIndex}`, payload.interpretation, `数据来源:${payload.dataSource}`, ]; if (payload.message) { lines.push(payload.message); } if (recommendation) { lines.push(`建议:${recommendation}`); } await notificationService.sendImmediateNotification({ title: `${config.emoji} ${config.title}`, body: lines.join('\n'), data: { type: NotificationTypes.HRV_STRESS_ALERT, stressLevel: payload.stressLevel, stressIndex: payload.stressIndex, hrvValue: payload.hrvValue, recordedAt: payload.recordedAt, url: '/(tabs)/statistics', }, sound: true, priority: config.priority ?? 'normal', }); }