export type ChatMessageType =
  | "text"
  | "file"
  | "image"
  | "audio"
  | "video"
  | "text_and_file";

export interface ChatParticipant {
  _id: string;
  firstname?: string;
  lastname?: string;
  image?: string;
  is_online?: boolean;
  currentUserType?: string;
  userType?: string;
  email?: string;
}

export interface ChatAttachment {
  url: string;
  type: "image" | "video" | "audio" | "file";
  fileName?: string;
  mimeType?: string;
  size?: number;
}

export interface ChatMessage {
  _id: string;
  conversationId: string;
  sender: ChatParticipant;
  content: string;
  messageType: ChatMessageType;
  attachments: ChatAttachment[];
  isRead: boolean;
  readBy: { user: string; readAt: string }[];
  isDeleted: boolean;
  createdAt: string;
  updatedAt: string;
  tempId?: string;
}

export interface ChatConversation {
  _id?: string;
  id?: string;
  participants: ChatParticipant[];
  lastMessage: ChatMessage | null;
  lastMessageTime: string | null;
  isActive: boolean;
  unreadCount?: number;
  isBlockedByMe?: boolean;
  isBlockedByOther?: boolean;
  isBlockedByBoth?: boolean;
}

export interface PaginatedConversations {
  conversations: ChatConversation[];
  totalDocs: number;
  currentPage: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPrevPage: boolean;
}

export interface PaginatedMessages {
  conversation: ChatConversation;
  messages: ChatMessage[];
  totalDocs: number;
  currentPage: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPrevPage: boolean;
}

export interface InboxListItem {
  id: string;
  conversationId: string;
  peer: ChatParticipant;
  name: string;
  image: string;
  lastMessage: string;
  time: string;
  sortTimestamp: string;
  unreadCount: number;
  isOnline: boolean;
  isTyping: boolean;
}

export interface InboxLivePatch {
  lastMessage?: string;
  time?: string;
  sortTimestamp?: string;
  unreadCount?: number;
  isTyping?: boolean;
}

export interface ApiEnvelope<T> {
  status: boolean;
  message: string;
  data: T;
}
