import { apiClient } from './client'; export interface Notification { id: string; userId: string; childId?: string; type: 'feeding_reminder' | 'sleep_reminder' | 'diaper_reminder' | 'medication_reminder' | 'milestone_alert' | 'growth_tracking' | 'appointment_reminder' | 'pattern_anomaly'; status: 'pending' | 'sent' | 'failed' | 'read' | 'dismissed'; priority: 'low' | 'medium' | 'high' | 'urgent'; title: string; message: string; metadata?: Record; scheduledFor?: string; sentAt?: string | null; readAt?: string | null; dismissedAt?: string | null; deviceToken?: string; errorMessage?: string; createdAt: string; updatedAt: string; } export interface GetNotificationsParams { limit?: number; status?: Notification['status']; includeRead?: boolean; } export interface GetNotificationsResponse { notifications: Notification[]; total: number; unreadCount: number; } // Backend response is wrapped in { success, data } interface BackendResponse { success: boolean; data: T; message?: string; } export const notificationsApi = { /** * Get user notifications with optional filters */ async getNotifications(params?: GetNotificationsParams): Promise { const { data } = await apiClient.get>('/notifications', { params }); const notifications = data.data.notifications; const unreadCount = notifications.filter(n => !n.readAt && !n.dismissedAt).length; return { notifications, total: notifications.length, unreadCount, }; }, /** * Mark a notification as read */ async markAsRead(notificationId: string): Promise { const { data } = await apiClient.patch>(`/notifications/${notificationId}/read`); // Backend returns success message, not the notification, so we return empty object return {} as Notification; }, /** * Mark all notifications as read */ async markAllAsRead(): Promise<{ count: number }> { await apiClient.patch>('/notifications/mark-all-read'); return { count: 0 }; // Backend doesn't return count }, /** * Dismiss a notification */ async dismiss(notificationId: string): Promise { await apiClient.patch>(`/notifications/${notificationId}/dismiss`); return {} as Notification; }, /** * Get unread notification count */ async getUnreadCount(): Promise { const response = await this.getNotifications({ limit: 100, includeRead: false }); return response.unreadCount; }, };