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

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

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