import { useQuery } from '@tanstack/react-query'
import api from '@/services/api'
import type { DashboardResponse, YearlyComparisonResponse, TopIcdResponse, TopGutachterResponse, GutachtenStatistikResponse } from '@/types'

export function useDashboard(jahr: number) {
  return useQuery({
    queryKey: ['dashboard', jahr],
    queryFn: () => api.get<DashboardResponse>('/reports/dashboard', { params: { jahr } }).then(r => r.data),
  })
}

export function useYearlyComparison() {
  return useQuery({
    queryKey: ['dashboard', 'yearly-comparison'],
    queryFn: () => api.get<YearlyComparisonResponse>('/reports/dashboard/yearly-comparison').then(r => r.data),
    staleTime: 60_000,
  })
}

export function useTopIcd(jahr: number) {
  return useQuery({
    queryKey: ['dashboard', 'top-icd', jahr],
    queryFn: () => api.get<TopIcdResponse>('/reports/dashboard/top-icd', { params: { jahr } }).then(r => r.data),
  })
}

export function useTopGutachter(jahr: number, enabled = true) {
  return useQuery({
    queryKey: ['dashboard', 'top-gutachter', jahr],
    queryFn: () => api.get<TopGutachterResponse>('/reports/dashboard/top-gutachter', { params: { jahr } }).then(r => r.data),
    enabled,
  })
}

export function useGutachtenStatistik(jahr: number) {
  return useQuery({
    queryKey: ['gutachten-statistik', jahr],
    queryFn: () => api.get<GutachtenStatistikResponse>('/reports/gutachten-statistik', { params: { jahr } }).then(r => r.data),
  })
}
