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

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

export function useIssueAssignees(
  workspaceName: string | null,
  number: number | null,
  limit = 50,
  offset = 0,
) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'issues', number, 'assignees', { limit, offset }],
    queryFn: () => {
      if (!workspaceName || number === null) throw new Error('Missing params');
      return IssuesService.issueListAssignees({ workspaceName, number, limit, offset }).then(
        (r) => r.data,
      );
    },
    enabled: !!workspaceName && number !== null,
  });
}
