/**
 * KB Accelerator types — converts KB articles into interactive flows.
 */

// ── Requests ──

export interface KBUploadTextRequest {
  content: string
  title?: string
  target_type?: 'troubleshooting' | 'procedural'
}

export interface KBNodeEditRequest {
  operation: 'approve' | 'reject' | 'edit' | 'delete' | 'regenerate' | 'insert_after'
  content?: Record<string, unknown>
  guidance?: string
}

export interface KBCommitRequest {
  name?: string
  description?: string
  category_id?: string
}

export interface KBListParams {
  skip?: number
  limit?: number
  status?: string
}

// ── Responses ──

export interface KBImportNode {
  id: string
  kb_import_id: string
  node_order: number
  node_type: string
  content: Record<string, unknown>
  parent_node_id: string | null
  source_excerpt: string | null
  confidence_score: number
  user_edited: boolean
  user_approved: boolean
}

export interface KBUploadResponse {
  id: string
  status: string
  source_format: string
}

export interface KBImport {
  id: string
  account_id: string
  created_by: string
  source_filename: string | null
  source_format: string
  source_text: string
  source_metadata: Record<string, unknown> | null
  target_type: string
  status: string
  confidence_avg: number | null
  error_message: string | null
  processing_time_ms: number | null
  ai_tokens_input: number | null
  ai_tokens_output: number | null
  tree_id: string | null
  nodes: KBImportNode[]
  created_at: string
  updated_at: string
}

export interface KBImportSummary {
  id: string
  source_filename: string | null
  source_format: string
  target_type: string
  status: string
  confidence_avg: number | null
  node_count: number
  created_at: string
}

export interface KBImportListResponse {
  items: KBImportSummary[]
  total: number
  skip: number
  limit: number
}

export interface KBCommitResponse {
  tree_id: string
  import_id: string
  tree_type: string
}

export interface KBQuotaResponse {
  plan: string
  kb_accelerator_enabled: boolean
  lifetime_conversions_used: number
  lifetime_conversions_limit: number | null
  allowed_formats: string[]
  detailed_analysis: boolean
  conversational_refinement: boolean
  step_library_matching: boolean
  history_limit: number | null
  can_convert: boolean
}
