"""
Platform-independent environment configuration loader for AZKees.

This module handles loading configuration paths based on the operating system,
ensuring consistent behavior across different platforms. It determines the
appropriate path for the API keys configuration file based on whether the
system is Windows or Linux.

Example:
    >>> from azkees.load_envs import keys_config
    >>> print(keys_config)
    'C:/path/to/config/api_keys.ini'  # On Windows
    '/app/api_keys.ini'               # On Linux
"""

import os
import platform
from dotenv import load_dotenv

load_dotenv()

IS_WINDOWS = platform.system() == "Windows"


def get_keys_config() -> str:
    """Return the config path from the appropriate environment variable.

    Returns:
        str: Path to the api_keys.ini config file.

    Raises:
        KeyError: If the required environment variable is not set.
    """
    env_var = "keys_config_windows" if IS_WINDOWS else "keys_config_linux"
    return os.environ[env_var]


# Lazy alias — only resolved when accessed, not at import time.
try:
    keys_config = get_keys_config()
except KeyError:
    keys_config = None
