import api from './client' export type NotificationChannel = 'notification' | 'activity' | 'alert' export interface Notification { id: string action: string entity_type: string | null entity_id: string | null details: Record | null timestamp: string read_at: string | null channel?: NotificationChannel } export interface NotificationListResponse { items: Notification[] unread_count: number total: number } export async function getNotifications(params?: { limit?: number offset?: number unread_only?: boolean channel?: NotificationChannel }): Promise { const { data } = await api.get('/notifications', { params }) return data } export async function getUnreadCount(): Promise { const { data } = await api.get<{ unread_count: number }>('/notifications/unread-count') return data.unread_count } export async function markAsRead(ids?: string[]): Promise { await api.post('/notifications/mark-read', { notification_ids: ids ?? null }) } export async function markOneAsRead(id: string): Promise { await api.post(`/notifications/${id}/mark-read`) } // ── Notification Config ─────────────────────────────────────────────────── export type NotificationFrequency = 'immediate' | 'daily' | 'never' export interface NotificationConfig { id: string user_id: string event_type: string channel: 'in_app' | 'email' enabled: boolean frequency: NotificationFrequency created_at: string } export async function getNotificationConfigs(): Promise { const res = await api.get('/notifications/config') return res.data } export async function updateNotificationConfig( eventType: string, channel: string, enabled: boolean, frequency?: NotificationFrequency ): Promise { const body: Record = { enabled } if (frequency !== undefined) body.frequency = frequency const res = await api.put( `/notifications/config/${encodeURIComponent(eventType)}/${channel}`, body ) return res.data } export async function resetNotificationConfigs(): Promise { const res = await api.post('/notifications/config/reset') return res.data }