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

from .gr4vyerror import Gr4vyError
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys

if TYPE_CHECKING:
    from .apierror import APIError
    from .error400 import Error400, Error400Data
    from .error401 import Error401, Error401Data
    from .error403 import Error403, Error403Data
    from .error404 import Error404, Error404Data
    from .error405 import Error405, Error405Data
    from .error409 import Error409, Error409Data
    from .error425 import Error425, Error425Data
    from .error429 import Error429, Error429Data
    from .error500 import Error500, Error500Data
    from .error502 import Error502, Error502Data
    from .error504 import Error504, Error504Data
    from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
    from .no_response_error import NoResponseError
    from .responsevalidationerror import ResponseValidationError

__all__ = [
    "APIError",
    "Error400",
    "Error400Data",
    "Error401",
    "Error401Data",
    "Error403",
    "Error403Data",
    "Error404",
    "Error404Data",
    "Error405",
    "Error405Data",
    "Error409",
    "Error409Data",
    "Error425",
    "Error425Data",
    "Error429",
    "Error429Data",
    "Error500",
    "Error500Data",
    "Error502",
    "Error502Data",
    "Error504",
    "Error504Data",
    "Gr4vyError",
    "HTTPValidationError",
    "HTTPValidationErrorData",
    "NoResponseError",
    "ResponseValidationError",
]

_dynamic_imports: dict[str, str] = {
    "APIError": ".apierror",
    "Error400": ".error400",
    "Error400Data": ".error400",
    "Error401": ".error401",
    "Error401Data": ".error401",
    "Error403": ".error403",
    "Error403Data": ".error403",
    "Error404": ".error404",
    "Error404Data": ".error404",
    "Error405": ".error405",
    "Error405Data": ".error405",
    "Error409": ".error409",
    "Error409Data": ".error409",
    "Error425": ".error425",
    "Error425Data": ".error425",
    "Error429": ".error429",
    "Error429Data": ".error429",
    "Error500": ".error500",
    "Error500Data": ".error500",
    "Error502": ".error502",
    "Error502Data": ".error502",
    "Error504": ".error504",
    "Error504Data": ".error504",
    "HTTPValidationError": ".httpvalidationerror",
    "HTTPValidationErrorData": ".httpvalidationerror",
    "NoResponseError": ".no_response_error",
    "ResponseValidationError": ".responsevalidationerror",
}


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)
