/**
 * @openchatlab/core
 *
 * 平台无关的 ChatLab 共享核心。
 * 提供抽象接口、查询工具、分析算法，不依赖任何特定运行时（Electron / Node / 浏览器）。
 */

// 抽象接口
export type { DatabaseAdapter, PreparedStatement, RunResult, PathProvider } from './interfaces'

// 查询工具
export {
  buildTimeFilter,
  buildSystemMessageFilter,
  hasTable,
  hasColumn,
  isChatSessionDb,
  getSessionMeta,
  getSessionOverview,
  getDatabaseSchema,
  getChatOverview,
  getSegmentMessages,
  getSegmentSummaries,
  buildSessionInfo,
  getSessionInfo,
  getSummaryCount,
  getLastPlatformMessageId,
  DEFAULT_SESSION_GAP_THRESHOLD,
  hasSessionIndex,
  getSessionIndexStats,
  getChatSessionList,
  getSessionsByTimeRange,
  getRecentChatSessions,
  loadSegmentMessages,
  getSegmentSummary,
  saveSegmentSummary,
  updateSessionGapThreshold,
  clearSessionIndex,
  generateSessionIndex,
  generateIncrementalSessionIndex,
  getPrivateChatMemberAvatar,
  getExportSessionData,
  getTimeRange,
  getAvailableYears,
  getMemberActivity,
  getHourlyActivity,
  getDailyActivity,
  getWeekdayActivity,
  getMessageTypeStats,
  getMonthlyActivity,
  getYearlyActivity,
  getMessageLengthDistribution,
  getTextStats,
  getLongMessageCount,
  getMemberMonthlyTrend,
  getTextLengthPercentiles,
  getGroupContactFacts,
  getLatestContactMessageTs,
  getNonSystemMembersForContacts,
  getPrivateContactFacts,
  isValidContactPlatformId,
  resolveOwnerMember,
  MIN_PRIVATE_SESSIONS_FOR_CONTACTS,
  computeFriendScore,
  computeFriendScores,
  computeNonFriendScore,
  computeNonFriendScores,
  computePrivateRegularity,
  rankPercentiles,
  queryMessages,
  searchMessagesLike,
  searchMessagesByKeywords,
  getRecentMessages,
  getMembers,
  getMembersDetailed,
  executeReadonlySql,
  executeSql,
  getSchemaDetailed,
  getMessageContext,
  getSearchMessageContext,
  getConversationBetween,
  getMemberNameHistory,
  getMembersWithAliases,
  getMembersPaginated,
  executeParameterizedSql,
  getCatchphraseAnalysis,
  getMentionAnalysis,
  getMentionGraph,
  getLaughAnalysis,
  getClusterGraph,
  getRelationshipStats,
  getLanguagePreferenceAnalysis,
  getDragonKingAnalysis,
  getDivingAnalysis,
  getCheckInAnalysis,
  getMemeBattleAnalysis,
  getNightOwlAnalysis,
  getRepeatAnalysis,
  FULL_MSG_COLUMNS,
  FULL_MSG_FROM,
  FULL_MSG_SELECT,
  MSG_COUNT_FROM,
  SYSTEM_MSG_FILTER,
  TEXT_ONLY_FILTER,
  mapMessageRow,
  buildMsgConditions,
  fetchMessagesBefore,
  fetchMessagesAfter,
  searchMessagesLikeAsync,
  searchMessagesWithFtsAsync,
  fetchMessageContext,
  fetchSearchMessageContext,
  fetchAllRecentMessages,
  fetchRecentTextMessages,
  fetchConversationBetween,
  updateMemberAliases,
  mergeMembers,
  deleteMember,
  ensureAliasesColumn,
  ensureAvatarColumn,
  updateSessionOwnerId,
  renameSession,
} from './query'

// 查询类型
export type {
  SessionMeta,
  SessionOverview,
  SessionInfo,
  CoreSessionInfo,
  ChatOverviewData,
  SegmentMessagesData,
  SegmentSummaryData,
  ChatSessionItem,
  SessionIndexStats,
  SessionPreviewMessage,
  MemberActivity,
  HourlyActivity,
  DailyActivity,
  WeekdayActivity,
  MessageTypeStats,
  MonthlyActivity,
  YearlyActivity,
  MessageLengthDistribution,
  TextStats,
  TextLengthPercentiles,
  MemberMonthlyTrend,
  ContactFactsOptions,
  ContactMemberRef,
  GroupContactFacts,
  PrivateContactFacts,
  ContactScoringResult,
  FriendScoreComponents,
  FriendScoreInput,
  NonFriendScoreComponents,
  NonFriendScoreInput,
  QueryMessagesOptions,
  QueryMessagesResult,
  MessageResult,
  PaginatedMessages,
  MemberDetailed,
  ContextMessage,
  ConversationData,
  MemberNameHistoryEntry,
  MemberWithAliases,
  MembersPaginationParams,
  MembersPaginatedResult,
  CatchphraseAnalysis,
  MemberCatchphrase,
  CatchphraseItem,
  MentionGraphData,
  MentionGraphNode,
  MentionGraphLink,
  ClusterGraphData,
  ClusterGraphNode,
  ClusterGraphLink,
  ClusterGraphOptions,
  RelationshipStats,
  RelationshipMonthStats,
  IceBreakerItem,
  ResponseLatencyMember,
  PerseveranceMember,
  MonthlyResponseLatency,
  MonthlyPerseverance,
  RelationshipOptions,
  NlpProvider,
  PosTagResult,
  LanguagePreferenceParams,
  NightOwlTitle,
  NightOwlRankItem,
  TimeRankItem,
  ConsecutiveNightRecord,
  NightOwlChampion,
  NightOwlAnalysis,
  DragonKingRankItem,
  DragonKingAnalysis,
  DivingRankItem,
  DivingAnalysis,
  RepeatStatItem,
  RepeatRateItem,
  ChainLengthDistribution,
  HotRepeatContent,
  FastestRepeaterItem,
  RepeatAnalysis,
  MemeBattleRankItem,
  MemeBattleRecord,
  MemeBattleAnalysis,
  StreakRankItem,
  LoyaltyRankItem,
  CheckInAnalysis,
  FullMessageRow,
  MappedMessage,
  MsgQueryConditions,
  AsyncSqlExecutor,
  AsyncPaginatedMessages,
  AsyncMessagesWithTotal,
  AsyncConversationData,
  SqlExecutionOptions,
  SqlExecutionResult,
  TableSchema,
} from './query'

// 版本比较
export { isNewerStableVersion, isStableVersion } from './version'
export type { ParsedStableVersion } from './version'

// Chart runtime
export { ChartValidationError, normalizeChartSpec, inferChartDataset, buildChartPayload } from './chart'
export type {
  ChartType,
  ChartFieldType,
  ChartField,
  ChartEncoding,
  ChartSpec,
  ChartDataset,
  ChartPayload,
  ChartRenderData,
  BarChartRenderData,
  LineChartRenderData,
  PieChartRenderData,
  HeatmapChartRenderData,
} from './chart'

// NLP（平台无关的类型、数据和工具函数）
export {
  POS_TAG_DEFINITIONS,
  MEANINGFUL_POS_TAGS,
  CHINESE_STOPWORDS,
  ENGLISH_STOPWORDS,
  JAPANESE_STOPWORDS,
  getStopwords,
  isStopword,
  cleanText,
  isValidWord,
} from './nlp'
export type {
  SupportedLocale,
  PosFilterMode,
  DictType,
  PosTagInfo,
  WordFrequencyItem,
  PosTagStat,
  WordFrequencyResult,
  WordFrequencyParams,
  SegmentOptions,
  BatchSegmentOptions,
  BatchSegmentResult,
  DictInfo,
} from './nlp'

// AI（内置工具目录、LLM 模型系统等静态数据）
export type { ToolCategory, BuiltinToolCatalogEntry } from './ai'
export { BUILTIN_TOOL_CATALOG, normalizeBuiltinToolName, normalizeBuiltinToolNames } from './ai'
export type {
  ProviderKind,
  ProviderDefinition,
  ModelCapability,
  ModelStatus,
  ModelRecommendedFor,
  ModelDefinition,
  ModelSlot,
} from './ai'
export {
  BUILTIN_PROVIDERS,
  getBuiltinProviderById,
  BUILTIN_MODELS,
  getBuiltinModelsByProvider,
  getBuiltinModelById,
  CHART_CAPABILITY_SKILL_ID,
  THINK_TAGS,
  extractThinkingContent,
  stripToolCallTags,
  stripAvatarFields,
  StreamingThinkTagParser,
  needsStreamingThinkParsing,
  getSupportedThinkingLevels,
  isReasoningModel,
  getThinkingCompat,
  MAX_PERSISTED_TOOL_RESULT_CHARS,
  extractToolResultText,
  truncateToolResultText,
} from './ai'
export type { StreamParserEvent, ThinkingLevel, ThinkingCompat } from './ai'
export type {
  EvidenceRetrievalMode,
  EvidenceStatus,
  EvidencePayloadStatus,
  EvidenceWarning,
  EvidenceTimeRangeMs,
  ChatEvidenceSource,
  ChatEvidenceGroup,
  ChatEvidencePayload,
} from './ai'

// Owner profile matching（跨会话"我是谁"识别）
export {
  NAME_MATCH_PLATFORMS,
  isNameMatchPlatform,
  normalizeOwnerName,
  collectCandidateNames,
  mergeConfirmedNames,
  matchOwnerProfile,
} from './owner'
export type { OwnerMatchCandidate, OwnerMatchResult } from './owner'

// Import utilities
export { generateMessageKey, buildMemberIdMap } from './import'

// Merger algorithms
export {
  getCollidingPlatformIds,
  getCollidingPlatformIdsFromMessages,
  normalizePlatformId,
  detectConflictsInMessages,
  mergeMembers as mergeMergerMembers,
  deduplicateAndSortMessages,
} from './merger'
export type {
  MergerMember,
  MergerMessage,
  MergeConflict,
  ConflictCheckResult,
  MergedMember,
  MergedMessage,
} from './merger'

// Schema 与迁移
export {
  CURRENT_SCHEMA_VERSION,
  CHAT_DB_TABLES,
  CHAT_DB_INDEXES,
  CHAT_DB_SCHEMA,
  FTS_TABLE_SCHEMA,
  getSchemaVersion,
  setSchemaVersion,
  needsMigration,
  runMigrations,
} from './schema'
export type { Migration } from './schema'
