import request from '@/utils/http'

export interface AuditEvent {
  id: string
  tenant_id: string | null
  request_id: string
  api_key_id: string | null
  api_key_name: string | null
  provider_code: string | null
  model: string | null
  protocol: string
  status_code: number | null
  prompt_tokens: number | null
  completion_tokens: number | null
  cost_microunits: number | null
  latency_ms: number | null
  labels: Record<string, unknown>
  recorded_at: string
}

export interface AuditPage {
  items: AuditEvent[]
  next_before: string
}

export interface DailyUsage {
  date: string
  api_key_id: string
  api_key_name: string
  provider_code: string
  model: string
  requests: number
  failed_requests: number
  prompt_tokens: number
  completion_tokens: number
  cost_microunits: number
}

export function fetchAuditEvents(params: Record<string, string | number | undefined>) {
  return request.get<AuditPage>({ url: '/api/v1/admin/audit-events', params })
}

export function fetchDailyUsage(params: Record<string, string | undefined>) {
  return request.get<DailyUsage[]>({ url: '/api/v1/admin/usage/daily', params })
}
