import api from './index'
import type { AxiosResponse } from 'axios'

/** 单个工具命令 */
export interface ToolCommand {
  name: string
  description: string
  parameters: Record<string, unknown>
}

/** 工具调用统计 */
export interface ToolStats {
  call_count: number
  error_count: number
  total_duration_ms: number
  avg_duration_ms: number
  error_rate: number
}

/** 工具信息 */
export interface ToolInfo {
  name: string
  display_name: string
  description: string
  category: string
  subcategory: string
  source: 'manifest' | 'agent'
  source_file: string
  tags: string[]
  enabled: boolean
  commands: ToolCommand[]
  stats: ToolStats | null
  config: Record<string, unknown>
}

/** 工具子分类 */
export interface ToolSubgroup {
  name: string
  display_name: string
  tools: ToolInfo[]
}

/** 工具大分类 */
export interface ToolCategory {
  name: string
  display_name: string
  subgroups: ToolSubgroup[]
}

/** 工具统计摘要 */
export interface ToolSummary {
  total_commands: number
  active_commands: number
  total_tools: number
  manifest_tools: number
  agent_tools: number
}

/** GET /api/tools 响应 */
export interface ToolsResponse {
  categories: ToolCategory[]
  summary: ToolSummary
}

export const toolsApi = {
  list: (): Promise<AxiosResponse<ToolsResponse>> => {
    return api.get('/api/tools')
  },
}
