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

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

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