// Notification channels
export enum NotificationChannel {
  EMAIL = 'email',
  PUSH = 'push',
  SMS = 'sms',
}

// Notification priorities
export enum NotificationPriority {
  LOW = 'low',
  NORMAL = 'normal',
  HIGH = 'high',
  URGENT = 'urgent',
}

// Notification status
export enum NotificationStatus {
  PENDING = 'pending',
  SENT = 'sent',
  DELIVERED = 'delivered',
  READ = 'read',
  FAILED = 'failed',
}

// Template types
export enum TemplateType {
  WELCOME = 'welcome',
  PASSWORD_RESET = 'password_reset',
  EMAIL_VERIFICATION = 'email_verification',
  SMS_VERIFICATION = 'sms_verification',
  PUSH_WELCOME = 'push_welcome',
  CUSTOM = 'custom',
}

// Notification recipient
export interface NotificationRecipient {
  userId: string;
  email?: string;
  phone?: string;
  fcmToken?: string;
  apnsToken?: string;
}

// Notification template
export interface NotificationTemplate {
  id: string;
  type: TemplateType;
  channel: NotificationChannel;
  subject?: string; // For email
  title?: string; // For push
  body: string;
  locale: string;
  variables: Record<string, string>;
  isActive: boolean;
}

// Notification preferences
export interface NotificationPreferences {
  userId: string;
  email: {
    enabled: boolean;
    categories: string[]; // e.g., ['marketing', 'transactional', 'alerts']
  };
  push: {
    enabled: boolean;
    categories: string[];
  };
  sms: {
    enabled: boolean;
    categories: string[];
  };
}

// Base notification interface
export interface BaseNotification {
  id: string;
  userId: string;
  channel: NotificationChannel;
  templateId: string;
  priority: NotificationPriority;
  status: NotificationStatus;
  metadata?: Record<string, unknown>;
  createdAt: Date;
  sentAt?: Date;
  deliveredAt?: Date;
  readAt?: Date;
  failedAt?: Date;
  errorMessage?: string;
}

// Email-specific notification
export interface EmailNotification extends BaseNotification {
  channel: NotificationChannel.EMAIL;
  to: string;
  subject: string;
  htmlBody?: string;
  textBody?: string;
  attachments?: Array<{
    filename: string;
    content: Buffer | string;
    mimeType?: string;
  }>;
}

// Push notification
export interface PushNotification extends BaseNotification {
  channel: NotificationChannel.PUSH;
  title: string;
  body: string;
  data?: Record<string, unknown>;
  badge?: number;
  sound?: string;
  fcmToken?: string;
  apnsToken?: string;
}

// SMS notification
export interface SMSNotification extends BaseNotification {
  channel: NotificationChannel.SMS;
  to: string;
  body: string;
  from?: string;
}

// Union type for all notification types
export type Notification = EmailNotification | PushNotification | SMSNotification;

// Rate limit configuration
export interface RateLimitConfig {
  maxPerWindow: number;
  windowMs: number;
  key: string; // User ID or template ID
}
