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

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

export function usePrLabels(workspaceName: string | null, repoName: string | null) {
  return useQuery({
    queryKey: ['workspace', workspaceName, 'repos', repoName, 'prs', 'labels'],
    queryFn: () => {
      if (!workspaceName || !repoName) throw new Error('Missing params');
      return PullRequestsService.prListLabels({ workspaceName, repoName }).then((r) => r.data);
    },
    enabled: !!workspaceName && !!repoName,
  });
}
