/**
 * 问题排查 API 类型
 */

/** 匹配案例 */
export interface MatchedCase {
  rank: number
  score: number
  project: string
  title: string
  file: string
  phenomenon: string
}

/** 排查请求 */
export interface TroubleshootRequest {
  project_name?: string
  system_type?: string
  apk_product?: string
  query: string
}

/** 排查响应 */
export interface TroubleshootResponse {
  success: boolean
  response: string
  matched_cases: MatchedCase[]
  filter_warnings?: string[]
  api_time: number
  offline?: boolean
}

/** 搜索请求 */
export interface SearchRequest {
  project_name?: string
  query: string
}

/** 搜索响应 */
export interface SearchResponse {
  success: boolean
  matched_cases: MatchedCase[]
  matched_count: number
  search_time: number
}

/** AI 分析请求 */
export interface AnalyzeRequest {
  project_name?: string
  system_type?: string
  apk_product?: string
  query: string
  matched_cases?: MatchedCase[]
}

/** AI 分析响应 */
export interface AnalyzeResponse {
  success: boolean
  response: string
  filter_warnings?: string[]
  api_time: number
  offline?: boolean
}

/** 健康检查响应 */
export interface HealthResponse {
  status: 'ok' | 'error'
  timestamp: string
  version: string
  offline_mode: boolean
  knowledge_base: {
    total_records: number
    last_update: string
  }
  search: {
    mode: string
    vector_loaded: boolean
    embedding_model: string
  }
  cache: {
    total_files: number
    total_size_mb: number
  }
  scheduler: {
    initialized: boolean
    running?: boolean
    job_count?: number
    reason?: string
    error?: string
  }
  components: {
    search_engine: string
    safety_filter: string
    cache_manager: string
  }
}

/** 缓存统计响应 */
export interface CacheStatsResponse {
  success: boolean
  stats: {
    total_files: number
    total_size_mb: number
    oldest: string | null
    newest: string | null
  }
}

/** 清除缓存响应 */
export interface CacheClearResponse {
  success: boolean
  message: string
  cleared_count: number
}

/** 导出请求 */
export interface ExportRequest {
  project_name?: string
  system_type?: string
  apk_product?: string
  query?: string
  matched_cases?: MatchedCase[]
  response?: string
}

/** 提交记录请求 */
export interface SubmitRequest {
  project_name: string
  system_type?: string
  apk_product?: string
  phenomenon: string
  troubleshoot_steps?: string
  root_cause?: string
  solution?: string
  recorder: string
}

/** 提交记录响应 */
export interface SubmitResponse {
  success: boolean
  message: string
  record_id: string
  file: string
}

/** SSE 流式分析事件 */
export interface AnalyzeStreamEvent {
  type: 'start' | 'matched_cases' | 'chunk' | 'done' | 'error'
  message?: string
  cases?: MatchedCase[]
  content?: string
  api_time?: number
  cached?: boolean
  offline?: boolean
}
