/**
 * Phase 2: 聊天模式相关类型定义
 */

import { Document } from './index'

/**
 * 聊天基础模式
 */
export type ChatBaseMode = 'general' | 'knowledge_base'

/**
 * 知识库工作模式
 */
export type KnowledgeBaseMode = 'full_text' | 'deep_read' | 'batch'

/**
 * 聊天页面状态
 */
export interface ChatPageState {
  // 基础模式
  baseMode: ChatBaseMode
  
  // 知识库配置
  selectedKbId?: string
  kbMode?: KnowledgeBaseMode
  
  // 全文阅读模式状态
  fullTextState?: FullTextModeState
  
  // 逐篇精读模式状态
  deepReadState?: DeepReadModeState
}

/**
 * 全文阅读模式状态
 */
export interface FullTextModeState {
  loadedDocs: Document[]
  totalFiles: number
  selectedFiles: number
  totalTokens: number
  usedTokens: number
  availableTokens: number
  reason: 'all_included' | 'file_limit' | 'token_limit'
}

/**
 * 逐篇精读模式状态
 */
export interface DeepReadModeState {
  selectedDocs: Document[]
  currentDocId: string
  currentDoc?: Document
  currentConversation: ChatMessage[]
  conversationPerDoc: Map<string, ChatMessage[]>
  totalTokens: number
}

/**
 * 聊天消息
 */
export interface ChatMessage {
  id: string
  role: 'user' | 'assistant' | 'system'
  content: string
  timestamp: Date
  metadata?: any
}

/**
 * 文档选择结果（从API返回）
 */
export interface DocumentSelectionResult {
  knowledgeBaseId: string
  knowledgeBaseName: string
  limits: {
    maxFiles: number
    maxTokens: number
  }
  selection: {
    selectedCount: number
    selectedTokens: number
    excludedCount: number
    availableTokens: number
    reason: 'all_included' | 'file_limit' | 'token_limit'
  }
  selectedDocuments: Document[]
  excludedDocuments: Document[]
}

