// Types de notifications push
export type NotificationType = 
  | 'message'           // Message dans une conversation (non stocké en BDD)
  | 'invitation'        // Invitation à rejoindre une conversation
  | 'mention'           // Mention dans un message de groupe
  | 'system'            // Notification système (maintenance, etc.)
  | 'announcement'      // Annonce importante
  | 'reminder'          // Rappel

// Payload de base pour toutes les notifications
export interface BaseNotificationPayload {
  type: NotificationType
  title: string
  body: string
  icon?: string
  badge?: string
  url: string
  timestamp: string
}

// Payload spécifique pour les notifications de message
export interface MessageNotificationPayload extends BaseNotificationPayload {
  type: 'message'
  conversationId: string
  senderMainId: number
  senderName: string
  messagePreview: string
}

// Payload spécifique pour les invitations
export interface InvitationNotificationPayload extends BaseNotificationPayload {
  type: 'invitation'
  invitationId: string
  inviterMainId: number
  inviterName: string
  conversationId?: string
  conversationName?: string
}

// Payload spécifique pour les mentions
export interface MentionNotificationPayload extends BaseNotificationPayload {
  type: 'mention'
  conversationId: string
  messageId: string
  mentionerMainId: number
  mentionerName: string
}

// Payload spécifique pour les notifications système
export interface SystemNotificationPayload extends BaseNotificationPayload {
  type: 'system'
  priority: 'low' | 'normal' | 'high' | 'urgent'
  actionUrl?: string
}

// Payload spécifique pour les annonces
export interface AnnouncementNotificationPayload extends BaseNotificationPayload {
  type: 'announcement'
  announcementId: string
  expiresAt?: string
}

// Payload spécifique pour les rappels
export interface ReminderNotificationPayload extends BaseNotificationPayload {
  type: 'reminder'
  reminderId: string
  relatedEntityId?: string
  relatedEntityType?: 'conversation' | 'task' | 'event'
}

// Union de tous les types de payload
export type NotificationPayload =
  | MessageNotificationPayload
  | InvitationNotificationPayload
  | MentionNotificationPayload
  | SystemNotificationPayload
  | AnnouncementNotificationPayload
  | ReminderNotificationPayload

// Fonction helper pour vérifier si une notification doit être stockée en BDD
export function shouldPersistNotification(type: NotificationType): boolean {
  // Les messages ne sont pas stockés (déjà dans la table messages)
  // Tous les autres types sont stockés
  return type !== 'message'
}

// Fonction helper pour obtenir la priorité par défaut selon le type
export function getNotificationPriority(type: NotificationType): 'low' | 'normal' | 'high' {
  switch (type) {
    case 'system':
      return 'high'
    case 'invitation':
    case 'mention':
      return 'normal'
    case 'message':
    case 'announcement':
    case 'reminder':
    default:
      return 'normal'
  }
}

// Fonction helper pour obtenir l'icône par défaut selon le type
export function getNotificationIcon(type: NotificationType): string {
  switch (type) {
    case 'message':
      return '/icons/message.svg'
    case 'invitation':
      return '/icons/invitation.svg'
    case 'mention':
      return '/icons/mention.svg'
    case 'system':
      return '/icons/system.svg'
    case 'announcement':
      return '/icons/announcement.svg'
    case 'reminder':
      return '/icons/reminder.svg'
    default:
      return '/next.svg'
  }
}

