from typing import Set

from im360.utils.net import is_ipv6_enabled
from defence360agent.utils.validate import IP, IPVersion

_state = {}  # type: Dict[IPVersion, bool]


def init() -> None:
    global _state
    _state = {IP.V4: True, IP.V6: is_ipv6_enabled()}


def enable(ip_version: IPVersion) -> None:
    _state[ip_version] = True


def disable(ip_version: IPVersion) -> bool:
    if ip_version == IP.V6:
        _state[ip_version] = False
        return True
    return False


def is_enabled(ip_version: IPVersion) -> bool:
    return _state[ip_version]


def enabled() -> Set[IPVersion]:
    return set(k for k, v in sorted(_state.items()) if v)


def all() -> Set[IPVersion]:
    return set(_state.keys())
