import { api } from './client'
import { createCachedGetter } from './cache'

const SYSTEM_STATS_TTL_MS = 15_000

const systemStatsGetter = createCachedGetter(async () => {
  const { data } = await api.get('/stats')
  return data
}, SYSTEM_STATS_TTL_MS)

export async function fetchSystemStats(options = {}) {
  return systemStatsGetter.run(options)
}

export function clearSystemStatsCache() {
  systemStatsGetter.clear()
}
