// Types globaux de l'application

export interface User {
  id: string;
  username: string;
  slug?: string;
  email: string;
  first_name?: string;
  last_name?: string;
  avatar?: string; // Backend uses 'avatar', not 'avatar_url'
  bio?: string;
  location?: string;
  birthdate?: string; // ISO8601 date string (nullable)
  gender?: string;
  username_changed_at?: string; // ISO8601 date string (nullable)
  role: 'user' | 'admin' | 'super_admin';
  is_active: boolean;
  is_verified: boolean;
  is_admin: boolean;
  is_public: boolean;
  last_login_at?: string; // ISO8601 date string (nullable)
  created_at: string; // ISO8601 date string
  updated_at: string; // ISO8601 date string
}

export interface AuthTokens {
  access_token: string;
  refresh_token: string;
  expires_in: number;
}

export interface LoginRequest {
  email: string;
  password: string;
}

export interface RegisterRequest {
  username: string;
  email: string;
  password: string;
  first_name?: string;
  last_name?: string;
}

export interface ChatMessage {
  id: string;
  conversation_id: string;
  sender_id: string;
  content: string;
  created_at: string;
  updated_at?: string;
  parent_message_id?: string;
  reactions?: MessageReaction[];
}

export interface MessageReaction {
  emoji: string;
  user_id: string;
  created_at: string;
}

export interface Conversation {
  id: string;
  name: string;
  description?: string;
  type: 'public' | 'private' | 'direct' | 'room' | 'dm'; // Support both frontend and backend types
  is_private?: boolean;
  created_by?: string;
  participants: string[];
  last_message?: ChatMessage;
  created_at: string;
  updated_at: string;
}

export interface Track {
  id: string;
  title: string;
  artist: string;
  duration: number;
  file_url: string;
  cover_url?: string;
  created_at: string;
  updated_at: string;
}

export interface LibraryItem {
  id: string;
  type: 'track' | 'document' | 'playlist';
  title: string;
  description?: string;
  file_url?: string;
  cover_url?: string;
  created_at: string;
  updated_at: string;
  is_favorite: boolean;
}

export interface ApiError {
  message: string;
  code?: string;
  details?: Record<string, unknown>;
}

export interface PaginatedResponse<T> {
  data: T[];
  total: number;
  page: number;
  limit: number;
  has_next: boolean;
  has_prev: boolean;
}

// WebSocket Events
export interface WebSocketEvent {
  type: string;
  data: unknown;
}

export interface ChatWebSocketEvent extends WebSocketEvent {
  type: 'message' | 'typing' | 'user_joined' | 'user_left' | 'reaction';
  data: {
    conversation_id: string;
    user_id: string;
    content?: string;
    emoji?: string;
    timestamp: string;
  };
}

// UI State
export interface UIState {
  theme: 'light' | 'dark' | 'system';
  language: 'en' | 'fr';
  sidebarOpen: boolean;
  notifications: Notification[];
}

export interface Notification {
  id: string;
  type: 'info' | 'success' | 'warning' | 'error';
  title: string;
  message: string;
  timestamp: string;
  read: boolean;
}

export interface ChatStats {
  active_users: number;
  total_messages: number;
  rooms_active?: number;
}
