import { apiFetch } from './client'; export interface WhatsAppStatus { session_id: string; tenant_id: string; session_name: string; status: string; battery_level?: number; last_ping_at?: string; } export interface WhatsAppQR { session_id: string; session_name: string; status: string; qr_code_base64?: string; } export interface NotificationLog { notification_id: string; tenant_id: string; recipient: string; channel: string; status: string; subject?: string; message_body: string; created_at: string; } export interface DeadLetterLog { dlq_id: string; tenant_id: string; notification_id: string; reason: string; failed_at: string; is_resolved: boolean; } export const notificationGatewayService = { getWhatsAppStatus: async () => { return apiFetch('/api/v1/notifications/whatsapp-gateway/status'); }, getWhatsAppQR: async () => { return apiFetch('/api/v1/notifications/whatsapp-gateway/qr'); }, getWhatsAppPairingCode: async (phoneNumber: string) => { return apiFetch<{ session_id: string; phone_number: string; pairing_code: string; status: string }>( `/api/v1/notifications/whatsapp-gateway/pairing-code?phoneNumber=${encodeURIComponent(phoneNumber)}`, { method: 'POST' } ); }, getNotificationLogs: async () => { return apiFetch('/api/v1/notifications/logs'); }, getDlqLogs: async () => { return apiFetch('/api/v1/notifications/dlq'); }, resolveDlq: async (dlqId: string) => { return apiFetch(`/api/v1/notifications/dlq/${dlqId}/resolve`, { method: 'POST', }); }, dispatch: async (payload: { recipient: string; channel: string; subject?: string; message_body: string }) => { return apiFetch('/api/v1/notifications/dispatch', { method: 'POST', body: JSON.stringify(payload), }); }, dispatchEntity: async (payload: { channel: 'EMAIL' | 'WHATSAPP' | 'BOTH'; notification_type: 'QUOTATION' | 'INVOICE' | 'REPAIR_TICKET' | 'LEAD_QUALIFIED'; entity_id: string; idempotency_key?: string; custom_note?: string; }) => { return apiFetch('/api/v1/notifications/dispatch-entity', { method: 'POST', body: JSON.stringify(payload), }); } };