//
// Created by spenc on 5/18/2025.
//

#ifndef OX_MACROS_H
#define OX_MACROS_H

#include <iostream>
#include <cstdlib>

// =====================
// Platform Breakpoints
// =====================
#if defined(_WIN32)
#define OX_DEBUG_BREAK() __debugbreak()
#elif defined(__unix__) || defined(__APPLE__)
    #include <signal.h>
    #define OX_DEBUG_BREAK() raise(SIGTRAP)
#else
    #define OX_DEBUG_BREAK() ((void)0)
#endif

// =====================
// ASSERT (debug-only)
// =====================
#ifdef _DEBUG
#define OX_ASSERT(condition, message)                                    \
    do {                                                                     \
        if (!(condition)) {                                                  \
            std::cerr << "\n\033[1;31m[ASSERTION FAILED]\033[0m "            \
                      << #condition << "\n"                                  \
                      << "Message: " << message << "\n"                      \
                      << "File: " << __FILE__ << ":" << __LINE__ << "\n";   \
            OX_DEBUG_BREAK();                                                \
        }                                                                    \
    } while (0)
#else
    #define OX_ASSERT(condition, message) ((void)0)
#endif

// =====================
// VERIFY (assert in debug, evaluates in release)
// =====================
#ifdef _DEBUG
#define OX_VERIFY(condition, message) OX_ASSERT(condition, message)
#else
    #define OX_VERIFY(condition, message) ((void)(condition))
#endif

// =====================
// always runs, logs if fails
// =====================
#define OX_ENSURE(condition, message)                                        \
do {                                                                         \
    if (!(condition)) {                                                      \
        std::cerr << "\n\033[1;33m[ENSURE FAILED]\033[0m "                   \
                  << #condition << "\n"                                      \
                  << "Message: " << message << "\n"                          \
                  << "File: " << __FILE__ << ":" << __LINE__ << "\n";       \
    }                                                                        \
} while (0)

#endif // OX_MACROS_H
