import importlib
import re
from datetime import datetime


def get_class(module_name, class_name):
    # 动态导入模块
    module = importlib.import_module(module_name)
    # 使用 getattr 从模块中获取类
    return getattr(module, class_name)


def camel_to_snake(name):
    # 将大写字母前加上下划线，并将整个字符串转换为小写
    return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()


def snake_to_camel(name):
    # 将下划线后的字母转换为大写，并删除下划线
    return ''.join(word.capitalize() for word in name.split('_'))


def default_serializer(obj):
    if isinstance(obj, datetime):
        return obj.strftime('%Y-%m-%d %H:%M:%S')
    raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable")
