// Types pour les données de chat

export type User = {
  id: number;
  name: string;
  avatar: string | null;
  email?: string;
  status: 'online' | 'offline' | 'away';
  lastSeen?: string;
};

export type Message = {
  id: number;
  conversationId: number;
  senderId: number;
  text: string;
  time: string;
  timestamp: number;
  isRead: boolean;
  attachments?: Attachment[];
};

export type Attachment = {
  id: number;
  type: 'image' | 'file' | 'video' | 'audio';
  url: string;
  name: string;
  size?: number;
};

export type Conversation = {
  id: number;
  name: string;
  avatar: string | null;
  isGroup: boolean;
  participants: number[]; // IDs des utilisateurs
  lastMessage: string;
  lastMessageTime: string;
  lastMessageTimestamp: number;
  unreadCount: number;
  isPinned?: boolean;
  isMuted?: boolean;
};

export type ConversationDetails = Conversation & {
  description?: string;
  createdAt: string;
  createdBy: number;
};

// Fonction utilitaire pour générer les initiales
export const getInitials = (name: string): string => {
  return name
    .split(' ')
    .map(word => word.charAt(0).toUpperCase())
    .slice(0, 2)
    .join('');
};

// Fonction utilitaire pour obtenir l'avatar ou les initiales
export const getAvatarOrInitials = (avatar: string | null, name: string): string => {
  if (avatar) {
    return avatar;
  }
  return getInitials(name);
};

