from enum import Enum
from importlib import import_module
from typing import Any


def create_object(
    module_name: str, class_name: str, *args: list[Any], **kwargs: dict[Any, Any]
) -> Any:
    module = import_module(module_name)

    cls = getattr(module, class_name)

    return cls(*args, **kwargs)


class LoggingError(Exception):
    pass


class LogLevel(Enum):
    DEBUG = "debug"
    INFO = "info"
    WARNING = "warning"
    ERROR = "error"
    CRITICAL = "critical"
    TRACE = "trace"


class RatelimitedError(Exception):
    default_detail = "Rate limit exceeded. Please try again later."
    default_code = "rate_limited"
    status_code = 429

    def __init__(self, detail: str | None = None, code: str | None = None):
        if detail is None:
            detail = self.default_detail
        if code is None:
            code = self.default_code

        self.detail: str | None = detail
        self.code: str | None = code
        super().__init__(detail)
