import request from '@/utils/http'

const METRICS_BASE_URL = '/api/admin/v1/dictionary/metrics'

export function getCacheStats(timeRange: '1h' | '24h' | '7d' = '1h') {
  return request.get<{
    totalHits: number
    totalMisses: number
    hitRatio: number
    hitsByLevel: { l1: number; l2: number }
    missesByLevel: { l1: number; l2: number }
    averageQueryDurationMs: number
    topQueriedDictionaries: Array<{ code: string; queryCount: number }>
  }>({
    url: `${METRICS_BASE_URL}/cache-stats`,
    params: { timeRange }
  })
}

export function getInvalidationEvents(params: {
  page: number
  pageSize: number
  startDate?: string
  endDate?: string
}) {
  return request.get<Api.Common.PageResult<Api.Dictionary.CacheInvalidationLogDto>>({
    url: `${METRICS_BASE_URL}/invalidation-events`,
    params: {
      page: params.page,
      pageSize: params.pageSize,
      startDate: params.startDate,
      endDate: params.endDate
    }
  })
}
