"""Platform detection utilities.

Centralizes platform checks so the rest of the codebase can use
``is_android()``, ``is_windows()``, etc. instead of ad-hoc
``sys.platform`` comparisons.

Android reports ``sys.platform == "linux"``, so a dedicated check is
needed to distinguish it from desktop Linux.
"""

import os
import sys

_is_android: bool | None = None


def is_android() -> bool:
    """Return True when running inside an Android environment (Chaquopy)."""
    global _is_android
    if _is_android is None:
        _is_android = hasattr(sys, "getandroidapilevel") or bool(os.environ.get("ANDROID_ROOT"))
    return _is_android


def is_windows() -> bool:
    """Return True on Windows."""
    return sys.platform == "win32"


def is_linux() -> bool:
    """Return True on desktop Linux (excludes Android)."""
    return sys.platform == "linux" and not is_android()


def is_macos() -> bool:
    """Return True on macOS."""
    return sys.platform == "darwin"
