import { useQuery } from '@tanstack/react-query';

import { WorkspacesService } from '@/client/services/WorkspacesService';

export function useWorkspaceStats(workspaceName: string | null) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'stats'],
    queryFn: () => {
      if (!workspaceName) throw new Error('No workspace name');
      return WorkspacesService.workspaceGetStats({ workspaceName }).then((r) => r.data);
    },
    enabled: !!workspaceName,
    staleTime: 1000 * 60 * 2,
  });
}
