// server/src/types.ts

export enum ModelType {
  LLM = 'llm',
  EMBEDDING = 'embedding',
  RERANK = 'rerank',
  VISION = 'vision',
}

// 1. Model Definition (The "Provider" setup)
export interface ModelConfig {
  id: string;
  name: string; // Display name, e.g. "My DeepSeek"
  modelId: string; // The actual string ID sent to API, e.g., "deepseek-chat"
  baseUrl?: string; // Base URL for OpenAI compatible API
  apiKey?: string; // API key for the service
  type: ModelType;
  dimensions?: number;
  supportsVision?: boolean;
  maxInputTokens?: number;
  maxBatchSize?: number;
  isVectorModel?: boolean;
  providerName?: string;
  isEnabled?: boolean;
  isDefault?: boolean;
}

// 2. Application Logic Settings (The "App" setup)
export interface AppSettings {
  // References to ModelConfig IDs
  selectedLLMId: string;
  selectedEmbeddingId: string; // Default for new uploads, and used for query encoding
  selectedRerankId: string;

  // Model Hyperparameters
  temperature: number;
  maxTokens: number;

  // Retrieval
  enableRerank: boolean;
  topK: number;
  similarityThreshold: number;
  rerankSimilarityThreshold: number;
  enableFullTextSearch: boolean;
  hybridVectorWeight: number;

  // Search Enhancement
  enableQueryExpansion: boolean;
  enableHyDE: boolean;

  chunkSize: number;
  chunkOverlap: number;

  // Language
  language: string;
}

// 3. Chat Stream Types (for streaming chat responses)
export type ChatStreamType = 
  | 'history'      // 上文：历史对话内容
  | 'sources'      // 引用：搜索结果来源
  | 'content'      // 正文：AI生成的回答
  | 'thinking'     // 深度思考：推理过程
  | 'status'       // 状态：搜索进度、调试信息
  | 'historyId';   // 历史ID：聊天会话ID

export interface ChatStreamChunk {
  type: ChatStreamType;
  data: any;
}

// History message structure
export interface HistoryMessage {
  role: 'user' | 'assistant';
  content: string;
}

// Source reference structure
export interface SourceReference {
  fileName: string;
  content: string;
  score: number;
  chunkIndex: number;
  fileId: string;
}

// Status message structure
export interface StatusMessage {
  stage: 'searching' | 'search_complete' | 'generating' | 'debug';
  message: string;
  details?: any;
}
