"""OS Detection Module - Detects and normalizes OS information."""

import platform
import sys
from typing import Dict, Literal


OSType = Literal["windows", "macos", "linux", "unknown"]


def detect_os() -> Dict[str, str]:
    """
    Detect the operating system and return normalized information.
    
    Returns:
        Dictionary with 'name', 'version', 'arch', and 'type' keys.
    """
    system = platform.system().lower()
    os_type: OSType = "unknown"
    
    if system == "windows":
        os_type = "windows"
    elif system == "darwin":
        os_type = "macos"
    elif system == "linux":
        os_type = "linux"
    
    return {
        "name": platform.system(),
        "version": platform.version(),
        "release": platform.release(),
        "arch": platform.machine(),
        "type": os_type,
        "platform": platform.platform()
    }


def is_windows() -> bool:
    """Check if running on Windows."""
    return platform.system().lower() == "windows"


def is_macos() -> bool:
    """Check if running on macOS."""
    return platform.system().lower() == "darwin"


def is_linux() -> bool:
    """Check if running on Linux."""
    return platform.system().lower() == "linux"
