"""InvestmentManager package; load CRM only when its blueprint API is requested.

The internal export engine can be imported without Flask, route registration,
or application startup. Existing ``from InvestmentManager import
investmentmanager_bp`` callers still receive the original CRM blueprint.
"""

__all__ = (
    "investmentmanager_bp",
    "CRM_API_PREFIXES",
    "crm_api_error",
    "is_crm_api_request",
    "require_crm_session",
    "add_no_cache_headers",
    "register_routes",
)


def __getattr__(name):
    if name not in __all__:
        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
    from importlib import import_module

    # Creating the blueprint must not import its routes: a route may itself be
    # the first module imported. The app factory loads all routes explicitly.
    blueprint_module = import_module("._blueprint", __name__)
    value = getattr(blueprint_module, name)
    globals()[name] = value
    return value
