import platform

# Detailed OS names reported in the rectype:2 "ver" tag.
# Keys are lowercased platform.system() values (same convention used by
# counter_manager and other modules that branch on platform.system()).
_OS_NAME_MAP = {
    "linux": "Linux",
    "windows": "Windows",
    "darwin": "OSX",
    "hp-ux": "HPUX",
    "aix": "AIX",
    "sunos": "Solaris",
}


def GetOSName():
    # Return the detailed OS name for the current execution environment.
    # Unix agent covers Linux / HPUX / AIX / Solaris.
    system = platform.system().lower()
    return _OS_NAME_MAP.get(system, system if system else "unknown")


def GetAgentVersion():
    # AGENT_VERSION is injected into counter_manager at startup by whatap_infrad.
    # Import lazily so this module has no import-time dependency on counter_manager
    # (avoids a circular import from the counter task modules).
    try:
        from whatap.agent.counter.counter_manager import AGENT_VERSION
        return AGENT_VERSION
    except Exception:
        return "unknown"


def GetVerTag():
    # Build the rectype:2 "ver" tag value: "[OS]_[Agent Version]" (e.g. "HPUX_1.4.11").
    return "{}_{}".format(GetOSName(), GetAgentVersion())
