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

from .squadcastsdkerror import SquadcastSDKError
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys

if TYPE_CHECKING:
    from .analytics_getorganalyticsop import (
        BadGatewayError,
        BadGatewayErrorData,
        BadRequest,
        BadRequestError,
        BadRequestErrorData,
        BadRequestUnion,
        ConflictError,
        ConflictErrorData,
        ForbiddenError,
        ForbiddenErrorData,
        GatewayTimeoutError,
        GatewayTimeoutErrorData,
        InternalServerError,
        InternalServerErrorData,
        NotFoundError,
        NotFoundErrorData,
        PaymentRequiredError,
        PaymentRequiredErrorData,
        ResponseBodyError1,
        ResponseBodyError1Data,
        ResponseBodyError2,
        ResponseBodyError2Data,
        ServiceUnavailableError,
        ServiceUnavailableErrorData,
        UnauthorizedError,
        UnauthorizedErrorData,
        UnprocessableEntityError,
        UnprocessableEntityErrorData,
    )
    from .common_v4_error import CommonV4Error, CommonV4ErrorData
    from .no_response_error import NoResponseError
    from .responsevalidationerror import ResponseValidationError
    from .sdkdefaulterror import SDKDefaultError

__all__ = [
    "BadGatewayError",
    "BadGatewayErrorData",
    "BadRequest",
    "BadRequestError",
    "BadRequestErrorData",
    "BadRequestUnion",
    "CommonV4Error",
    "CommonV4ErrorData",
    "ConflictError",
    "ConflictErrorData",
    "ForbiddenError",
    "ForbiddenErrorData",
    "GatewayTimeoutError",
    "GatewayTimeoutErrorData",
    "InternalServerError",
    "InternalServerErrorData",
    "NoResponseError",
    "NotFoundError",
    "NotFoundErrorData",
    "PaymentRequiredError",
    "PaymentRequiredErrorData",
    "ResponseBodyError1",
    "ResponseBodyError1Data",
    "ResponseBodyError2",
    "ResponseBodyError2Data",
    "ResponseValidationError",
    "SDKDefaultError",
    "ServiceUnavailableError",
    "ServiceUnavailableErrorData",
    "SquadcastSDKError",
    "UnauthorizedError",
    "UnauthorizedErrorData",
    "UnprocessableEntityError",
    "UnprocessableEntityErrorData",
]

_dynamic_imports: dict[str, str] = {
    "BadGatewayError": ".analytics_getorganalyticsop",
    "BadGatewayErrorData": ".analytics_getorganalyticsop",
    "BadRequest": ".analytics_getorganalyticsop",
    "BadRequestError": ".analytics_getorganalyticsop",
    "BadRequestErrorData": ".analytics_getorganalyticsop",
    "BadRequestUnion": ".analytics_getorganalyticsop",
    "ConflictError": ".analytics_getorganalyticsop",
    "ConflictErrorData": ".analytics_getorganalyticsop",
    "ForbiddenError": ".analytics_getorganalyticsop",
    "ForbiddenErrorData": ".analytics_getorganalyticsop",
    "GatewayTimeoutError": ".analytics_getorganalyticsop",
    "GatewayTimeoutErrorData": ".analytics_getorganalyticsop",
    "InternalServerError": ".analytics_getorganalyticsop",
    "InternalServerErrorData": ".analytics_getorganalyticsop",
    "NotFoundError": ".analytics_getorganalyticsop",
    "NotFoundErrorData": ".analytics_getorganalyticsop",
    "PaymentRequiredError": ".analytics_getorganalyticsop",
    "PaymentRequiredErrorData": ".analytics_getorganalyticsop",
    "ResponseBodyError1": ".analytics_getorganalyticsop",
    "ResponseBodyError1Data": ".analytics_getorganalyticsop",
    "ResponseBodyError2": ".analytics_getorganalyticsop",
    "ResponseBodyError2Data": ".analytics_getorganalyticsop",
    "ServiceUnavailableError": ".analytics_getorganalyticsop",
    "ServiceUnavailableErrorData": ".analytics_getorganalyticsop",
    "UnauthorizedError": ".analytics_getorganalyticsop",
    "UnauthorizedErrorData": ".analytics_getorganalyticsop",
    "UnprocessableEntityError": ".analytics_getorganalyticsop",
    "UnprocessableEntityErrorData": ".analytics_getorganalyticsop",
    "CommonV4Error": ".common_v4_error",
    "CommonV4ErrorData": ".common_v4_error",
    "NoResponseError": ".no_response_error",
    "ResponseValidationError": ".responsevalidationerror",
    "SDKDefaultError": ".sdkdefaulterror",
}


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)
