/**
 * 文档检索相关类型定义
 * 包含搜索请求参数、筛选条件、搜索结果条目、聚合统计和分页响应等结构。
 */

/** 搜索范围：全部 / 仅标题 / 仅正文 / 仅文号 */
export type SearchScope = 'all' | 'title' | 'content' | 'doc_number'

/** 高级筛选条件 */
export interface SearchFilters {
  issuing_org?: string[] | string
  doc_type?: string[] | string
  knowledge_category?: string[] | string
  document_scene_type?: string[] | string
  signer?: string
  publish_year?: number
  doc_number?: string
  date_from?: string
  date_to?: string
  subject_words?: string[]
  search_scope?: SearchScope
}

/** 搜索请求参数 */
export interface SearchParams {
  query: string
  filters?: SearchFilters
  page?: number
  page_size?: number
}

/** 命中的文档块详情（含页码、段落信息） */
export interface MatchedChunk {
  text: string
  page_number?: number | null
  page_numbers?: number[]
  heading_hierarchy?: string[]
  element_type?: string
  chunk_index?: number | null
}

/** 单条文档搜索结果 */
export interface DocumentResult {
  doc_id: string
  content_hash: string
  version_count: number
  title: string
  doc_number?: string
  knowledge_category?: string
  issuing_org?: string
  doc_type?: string
  publish_date?: string
  subject_words?: string[]
  score?: number
  highlights: string[]
  matched_chunks?: MatchedChunk[]
}

export interface AggregationBucket {
  key: string
  count: number
}

export interface SearchAggregations {
  [key: string]: AggregationBucket[]
}

/** 搜索接口分页响应 */
export interface SearchResponse {
  total: number
  page: number
  page_size: number
  documents: DocumentResult[]
  aggregations: SearchAggregations
}
