import functools

from .errors.common import InvalidVersion
from .version import version_lt


def minimum_version(version):
    def decorator(f):
        @functools.wraps(f)
        def wrapper(self, *args, **kwargs):
            if version_lt(self._server_version, version):
                raise InvalidVersion(
                    '{0} is only available on NETLAB+ systems version {1} or later.'.format(
                        f.__name__, version
                    )
                )
            return f(self, *args, **kwargs)
        return wrapper
    return decorator
