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

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

export function useIssueComments(workspaceName: string | null, number: number | null, limit = 50) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'issues', number, 'comments', { limit }],
    queryFn: () => {
      if (!workspaceName || number === null) throw new Error('Missing params');
      return IssuesService.issueListComments({ workspaceName, number, limit }).then((r) => r.data);
    },
    enabled: !!workspaceName && number !== null,
    staleTime: 1000 * 60 * 2,
  });
}
