/** * Notification Service * API client for notifications management */ import { apiClient as api } from '../lib/apiClient'; // ============================================================================ // Types // ============================================================================ export type NotificationType = | 'alert_triggered' | 'trade_executed' | 'deposit_confirmed' | 'withdrawal_completed' | 'distribution_received' | 'system_announcement' | 'security_alert' | 'account_update'; export type NotificationPriority = 'low' | 'normal' | 'high' | 'urgent'; export type NotificationIconType = 'success' | 'warning' | 'error' | 'info'; export interface Notification { id: string; userId: string; type: NotificationType; title: string; message: string; priority: NotificationPriority; data?: Record; actionUrl?: string; iconType: NotificationIconType; channels: string[]; isRead: boolean; readAt?: string; createdAt: string; } export interface NotificationPreferences { userId: string; emailEnabled: boolean; pushEnabled: boolean; inAppEnabled: boolean; smsEnabled: boolean; quietHoursStart?: string; quietHoursEnd?: string; disabledTypes: NotificationType[]; } export interface GetNotificationsParams { limit?: number; offset?: number; unreadOnly?: boolean; } interface ApiResponse { success: boolean; data: T; error?: string; } // ============================================================================ // Notification API // ============================================================================ /** * Get user notifications */ export async function getNotifications( params: GetNotificationsParams = {} ): Promise { const response = await api.get>('/notifications', { params }); return response.data.data; } /** * Get unread notification count */ export async function getUnreadCount(): Promise { const response = await api.get>('/notifications/unread-count'); return response.data.data.count; } /** * Mark notification as read */ export async function markAsRead(notificationId: string): Promise { await api.patch(`/notifications/${notificationId}/read`); } /** * Mark all notifications as read */ export async function markAllAsRead(): Promise { const response = await api.post>('/notifications/read-all'); return response.data.data.markedCount; } /** * Delete notification */ export async function deleteNotification(notificationId: string): Promise { await api.delete(`/notifications/${notificationId}`); } /** * Get notification preferences */ export async function getPreferences(): Promise { const response = await api.get>('/notifications/preferences'); return response.data.data; } /** * Update notification preferences */ export async function updatePreferences( preferences: Partial> ): Promise { const response = await api.patch>( '/notifications/preferences', preferences ); return response.data.data; } /** * Register push notification token */ export async function registerPushToken( token: string, platform: 'web' | 'ios' | 'android', deviceInfo?: Record ): Promise { await api.post('/notifications/push-token', { token, platform, deviceInfo }); } /** * Remove push notification token */ export async function removePushToken(token: string): Promise { await api.delete('/notifications/push-token', { data: { token } }); } // ============================================================================ // Export as object for convenience // ============================================================================ export const notificationApi = { getNotifications, getUnreadCount, markAsRead, markAllAsRead, deleteNotification, getPreferences, updatePreferences, registerPushToken, removePushToken, };