import importlib


def get_wrapper_class(hyperparams):
    """
    Get a Gym environment wrapper class specified as a hyper parameter
    "env_wrapper".
    e.g.
    env_wrapper: gym_minigrid.wrappers.FlatObsWrapper

    :param hyperparams: (dict)
    :return: a subclass of gym.Wrapper (class object) you can use to
             create another Gym env giving an original env.
    """

    def get_module_name(fullname):
        return '.'.join(wrapper_name.split('.')[:-1])

    def get_class_name(fullname):
        return wrapper_name.split('.')[-1]

    if 'env_wrapper' in hyperparams.keys():
        wrapper_name = hyperparams.get('env_wrapper')
        wrapper_module = importlib.import_module(get_module_name(wrapper_name))
        return getattr(wrapper_module, get_class_name(wrapper_name))
    else:
        return None