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

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

export function useRepoForks(
  workspaceName: string | null,
  repoName: string | null,
  limit = 50,
  offset = 0,
) {
  return useQuery({
    queryKey: ['repo', workspaceName, repoName, 'forks', { limit, offset }],
    queryFn: () => {
      if (!workspaceName || !repoName) throw new Error('Missing params');
      return ReposService.repoListForks({ workspaceName, repoName, limit, offset }).then(
        (r) => r.data,
      );
    },
    enabled: !!workspaceName && !!repoName,
  });
}
