"""Platform layer for multi-tenant SaaS capabilities around existing apps.

This package intentionally wraps the legacy applications without requiring
changes inside ``/apps``. It provides request context, tenant resolution,
routing, quotas, secrets, jobs, and structured logging primitives that can be
adopted incrementally by the main Flask entry point.

The directory name is intentionally ``platform/`` to match the requested SaaS
architecture. Because that collides with Python's standard-library
``platform`` module, this package exposes stdlib-compatible attributes at the
top level so existing imports like ``import platform; platform.system()`` keep
working while subpackages such as ``platform.gateway`` remain available.
"""

from __future__ import annotations

import importlib.util
import sysconfig
from pathlib import Path


def _load_stdlib_platform():
    stdlib_path = Path(sysconfig.get_path("stdlib")) / "platform.py"
    spec = importlib.util.spec_from_file_location("_stdlib_platform", stdlib_path)
    if spec is None or spec.loader is None:
        raise RuntimeError(f"Unable to load stdlib platform module from {stdlib_path}")
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


_stdlib_platform = _load_stdlib_platform()

# Mirror the public stdlib API unless the name is already defined locally.
for _name in dir(_stdlib_platform):
    if _name.startswith("_"):
        continue
    globals().setdefault(_name, getattr(_stdlib_platform, _name))

__all__ = [name for name in globals() if not name.startswith("_")]
