from .configuration import Configuration
from .client import WhatsrbCloud
from .errors import (
    WhatsrbCloudError,
    AuthenticationError,
    ForbiddenError,
    NotFoundError,
    ValidationError,
    ConflictError,
    ServerError,
    RateLimitError,
)
from .webhook_signature import WebhookSignature
from .action_registry import ActionRegistry
from .event_registry import EventRegistry

__version__ = "0.1.0"

_global_configuration = Configuration()
_default_client = None


def configure(
    *,
    api_key: str | None = None,
    base_url: str | None = None,
    timeout: int | None = None,
) -> None:
    global _default_client
    if api_key is not None:
        _global_configuration.api_key = api_key
    if base_url is not None:
        _global_configuration.base_url = base_url
    if timeout is not None:
        _global_configuration.timeout = timeout
    _default_client = None


def client() -> WhatsrbCloud:
    global _default_client
    if _default_client is None:
        _default_client = WhatsrbCloud()
    return _default_client


def reset_configuration() -> None:
    global _global_configuration, _default_client
    _global_configuration = Configuration()
    _default_client = None


__all__ = [
    "__version__",
    "configure",
    "client",
    "reset_configuration",
    "WhatsrbCloud",
    "Configuration",
    "WhatsrbCloudError",
    "AuthenticationError",
    "ForbiddenError",
    "NotFoundError",
    "ValidationError",
    "ConflictError",
    "ServerError",
    "RateLimitError",
    "WebhookSignature",
    "ActionRegistry",
    "EventRegistry",
]
