import { queryOptions } from '@tanstack/react-query';
import { useApi } from '../api/Api';
import { ERRORS } from '../components/Error/Errors';

export const usersQueryOptions = (Api: ReturnType<typeof useApi>, page?: number) =>
  queryOptions({
    queryKey: ['users', { page: page ?? 0 }],
    queryFn: async () => await Api.users(page),
    retry: (count, error) => ('code' in error && error.code !== ERRORS.UNAUTHORIZED ? count < 3 : false),
  });
