#include <windows.h>
#include <fmt/printf.h>
#include <string>
#include <type_traits>

template <typename CharType, typename... Args>
void GlobalOutputDebugString(const CharType* format, Args... args) {
    // 使用 fmt::sprintf 格式化字符串
    std::basic_string<CharType> formatted = fmt::sprintf(format, args...);

    // 根据字符类型调用相应的 OutputDebugString 函数
    if constexpr (std::is_same_v<CharType, char>) {
        OutputDebugStringA(formatted.c_str());
    } else if constexpr (std::is_same_v<CharType, wchar_t>) {
        OutputDebugStringW(formatted.c_str());
    }
}

// 这个宏将根据项目设置自动选择正确的字符类型。
// 如果项目设置为使用 Unicode 字符集,那么 _T 和 __FUNCTIONT__ 将解析为 L 和 __FUNCTIONW__。
// 如果项目设置为使用多字节字符集,那么 _T 和 __FUNCTIONT__ 将解析为无前缀和 __FUNCTION__。
#define LOG_DEBUG(format, ...) GlobalOutputDebugString(_T("[%d] ") __FUNCTIONT__ _T("(%d) ") format, GetCurrentThreadId(), __LINE__, ##__VA_ARGS__)