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

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

export function useRepoBranches(workspaceName: string | null, repoName: string | null) {
  return useQuery({
    queryKey: ['repo', workspaceName, repoName, 'branches'],
    queryFn: () => {
      if (!workspaceName || !repoName) throw new Error('Missing params');
      return ReposService.repoListBranches({ workspaceName, repoName, limit: 100 }).then(
        (r) => r.data.branches,
      );
    },
    enabled: !!workspaceName && !!repoName,
  });
}
