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

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

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