import { apiFetch } from './client'; export interface EventVariable { name: string; description: string; example: string; } export interface EventRegistry { event_key: string; description: string; variables: EventVariable[]; } export interface NotificationTemplate { template_id: string; tenant_id: string; event_key: string; name: string; channel: string; subject?: string; body_content: string; variables: string[]; is_active: boolean; created_at: string; updated_at: string; } export interface NotificationTemplateCreate { event_key: string; name: string; channel: string; subject?: string; body_content: string; is_active: boolean; } export interface NotificationTemplateUpdate { name?: string; subject?: string; body_content?: string; is_active?: boolean; } export const notificationTemplateService = { getEvents: async (): Promise => { return apiFetch('/api/v1/notification-templates/events'); }, getTemplates: async (): Promise => { return apiFetch('/api/v1/notification-templates'); }, createTemplate: async (data: NotificationTemplateCreate): Promise => { return apiFetch('/api/v1/notification-templates', { method: 'POST', body: JSON.stringify(data) }); }, updateTemplate: async (id: string, data: NotificationTemplateUpdate): Promise => { return apiFetch(`/api/v1/notification-templates/${id}`, { method: 'PUT', body: JSON.stringify(data) }); }, toggleActivation: async (id: string, isActive: boolean): Promise => { return apiFetch(`/api/v1/notification-templates/${id}/${isActive ? 'activate' : 'deactivate'}`, { method: 'PATCH' }); }, previewTemplateRaw: async (body_content: string, context: Record, subject?: string): Promise<{ subject: string; body: string }> => { const params = new URLSearchParams(); params.append('body_content', body_content); if (subject) params.append('subject', subject); return apiFetch<{ subject: string; body: string }>(`/api/v1/notification-templates/preview?${params.toString()}`, { method: 'POST', body: JSON.stringify({ context }) }); } };