import axios from 'axios'
import type { DataSourceConfig } from '@/stores/templateStore'

const api = axios.create({
  baseURL: '/api',
  timeout: 30000
})

/**
 * 获取所有数据源配置
 */
export async function listDataSources(): Promise<{ sources: DataSourceConfig[] }> {
  const response = await api.get<{ sources: DataSourceConfig[] }>('/config/data-sources')
  return response.data
}

/**
 * 获取指定数据源配置
 * @param filename 配置文件名（不含 .yaml 扩展名）
 */
export async function getDataSource(filename: string): Promise<DataSourceConfig> {
  const response = await api.get<DataSourceConfig>(`/config/data-sources/${filename}`)
  return response.data
}

/**
 * 健康检查
 */
export async function healthCheck(): Promise<{ status: string; service: string }> {
  const response = await api.get('/config/health')
  return response.data
}
