/**
 * 消息模块统一导出
 * 
 * 重构说明：
 * - 移除了 MessageStateManager 包装层
 * - 直接使用 zustand store 进行状态管理
 * - 服务层移至 services/ 目录
 * - 新增 hooks.ts 封装常用逻辑
 * - 移除了 SubscriptionManager，改用 Zustand selector 进行响应式订阅
 */

// ==================== 主管理器 ====================
export { messageManager, MessageManager } from './MessageManager';

// ==================== 状态管理 ====================
export {
  useMessageStore,
  normalizeConversationId,
  mergeMessagesById,
} from './store';
export type { MessageState, MessageActions, MessageStore } from './store';

// ==================== 类型导出 ====================
// 从 types.ts 导出所有类型
export type {
  MessageManagerState,
  ReadStateRecord,
  MessageManagerConversationListDeps,
  HandleNewMessageOptions,
  IMessageDeduplication,
  IUserCacheService,
  IReadReceiptManager,
  IConversationOperations,
  IMessageSendService,
  IMessageSyncService,
  IWSMessageHandler,
} from './types';

// ==================== 常量导出 ====================
export {
  READ_STATE_PROTECTION_DELAY,
  PROCESSED_MESSAGE_ID_EXPIRY,
  PROCESSED_MESSAGE_ID_MAX_SIZE,
  MAX_FLUSH_ITERATIONS,
  CONVERSATION_REFRESH_THROTTLE,
  MIN_RECONNECT_SYNC_INTERVAL,
} from './constants';

// ==================== 服务导出 ====================
export {
  // 消息去重服务
  MessageDeduplication,
  messageDeduplication,
  
  // 用户缓存服务
  UserCacheService,
  userCacheService,
  
  // 已读回执管理器
  ReadReceiptManager,
  
  // 会话操作服务
  ConversationOperations,
  
  // 消息发送服务
  MessageSendService,
  
  // 消息同步服务
  MessageSyncService,
  
  // WebSocket 消息处理器
  WSMessageHandler,
} from './services';

// ==================== Hooks 导出（便捷版，使用 messageManager 单例） ====================
export {
  // 会话相关
  useConversations,
  useConversation,
  useCreateConversation,
  useUpdateConversation,
  
  // 消息相关
  useMessages,
  useSendMessage,
  useMarkAsRead,
  
  // 未读数相关
  useUnreadCount,
  useTotalUnreadCount,
  useSystemUnreadCount,
  
  // 群聊相关
  useGroupTyping,
  useGroupMuted,
  
  // 通用
  useMessageManager,
  useMessageListRefresh,
  useChat,
  useMessageList,
} from './hooks';

// ==================== 数据源导出 ====================
export {
  CONVERSATION_LIST_PAGE_SIZE,
  type ConversationListPage,
  type IConversationListPagedSource,
  type RemoteConversationListSourceKind,
  NetworkRemoteConversationListPagedSource,
  SqliteConversationListPagedSource,
  createRemoteConversationListSource,
} from './sources';

// ==================== 默认导出 ====================
export { default } from './MessageManager';
