"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys

if TYPE_CHECKING:
    from .richiestaoperazione import (
        Accesso,
        AccessoTypedDict,
        Coordinate,
        CoordinateTypedDict,
        Richiesta,
        RichiestaOperazione,
        RichiestaOperazioneTypedDict,
        RichiestaTypedDict,
    )
    from .rispostaoperazione import (
        Dati,
        DatiTypedDict,
        RispostaOperazione,
        RispostaOperazioneTypedDict,
    )
    from .security import Security, SecurityTypedDict
    from .show_statusop import ShowStatusResponse, ShowStatusResponseTypedDict

__all__ = [
    "Accesso",
    "AccessoTypedDict",
    "Coordinate",
    "CoordinateTypedDict",
    "Dati",
    "DatiTypedDict",
    "Richiesta",
    "RichiestaOperazione",
    "RichiestaOperazioneTypedDict",
    "RichiestaTypedDict",
    "RispostaOperazione",
    "RispostaOperazioneTypedDict",
    "Security",
    "SecurityTypedDict",
    "ShowStatusResponse",
    "ShowStatusResponseTypedDict",
]

_dynamic_imports: dict[str, str] = {
    "Accesso": ".richiestaoperazione",
    "AccessoTypedDict": ".richiestaoperazione",
    "Coordinate": ".richiestaoperazione",
    "CoordinateTypedDict": ".richiestaoperazione",
    "Richiesta": ".richiestaoperazione",
    "RichiestaOperazione": ".richiestaoperazione",
    "RichiestaOperazioneTypedDict": ".richiestaoperazione",
    "RichiestaTypedDict": ".richiestaoperazione",
    "Dati": ".rispostaoperazione",
    "DatiTypedDict": ".rispostaoperazione",
    "RispostaOperazione": ".rispostaoperazione",
    "RispostaOperazioneTypedDict": ".rispostaoperazione",
    "Security": ".security",
    "SecurityTypedDict": ".security",
    "ShowStatusResponse": ".show_statusop",
    "ShowStatusResponseTypedDict": ".show_statusop",
}


def dynamic_import(modname, retries=3):
    for attempt in range(retries):
        try:
            return import_module(modname, __package__)
        except KeyError:
            # Clear any half-initialized module and retry
            sys.modules.pop(modname, None)
            if attempt == retries - 1:
                break
    raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")


def __getattr__(attr_name: str) -> object:
    module_name = _dynamic_imports.get(attr_name)
    if module_name is None:
        raise AttributeError(
            f"No {attr_name} found in _dynamic_imports for module name -> {__name__} "
        )

    try:
        module = dynamic_import(module_name)
        result = getattr(module, attr_name)
        return result
    except ImportError as e:
        raise ImportError(
            f"Failed to import {attr_name} from {module_name}: {e}"
        ) from e
    except AttributeError as e:
        raise AttributeError(
            f"Failed to get {attr_name} from {module_name}: {e}"
        ) from e


def __dir__():
    lazy_attrs = builtins.list(_dynamic_imports.keys())
    return builtins.sorted(lazy_attrs)
