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

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

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