// Messenger type definitions

export interface MessengerRoom {
  id: number;
  company_code: string;
  room_type: 'dm' | 'group' | 'channel';
  room_name: string | null;
  created_by: string;
  created_at: string;
  updated_at: string;
  // joined fields
  last_message?: string;
  last_message_at?: string;
  last_sender_id?: string;
  unread_count?: number;
  participants?: MessengerParticipant[];
}

export interface MessengerParticipant {
  id: number;
  room_id: number;
  user_id: string;
  company_code: string;
  last_read_at: string;
  joined_at: string;
  // joined fields
  user_name?: string;
  dept_name?: string;
  photo?: string | null;
}

export interface MessengerMessage {
  id: number;
  room_id: number;
  sender_id: string;
  company_code: string;
  content: string | null;
  message_type: 'text' | 'file' | 'system';
  parent_message_id: number | null;
  created_at: string;
  updated_at: string;
  // joined fields
  sender_name?: string;
  sender_photo?: string | null;
  reactions?: MessengerReaction[];
  files?: MessengerFile[];
  thread_count?: number;
}

export interface MessengerReaction {
  id: number;
  message_id: number;
  user_id: string;
  emoji: string;
  created_at: string;
}

export interface MessengerFile {
  id: number;
  message_id: number;
  original_name: string;
  stored_name: string;
  file_path: string;
  file_size: number;
  mime_type: string | null;
  created_at: string;
}

// Request types
export interface CreateRoomRequest {
  room_type: 'dm' | 'group' | 'channel';
  room_name?: string;
  participant_ids: string[];
}

export interface SendMessageRequest {
  content: string;
  message_type?: 'text' | 'file' | 'system';
  parent_message_id?: number;
}

export interface AddReactionRequest {
  message_id: number;
  emoji: string;
}

export interface UpdateRoomRequest {
  room_name: string;
}

export interface MessengerUser {
  user_id: string;
  user_name: string;
  dept_name: string;
  email?: string;
  photo?: string | null;
}
