#ifndef UTILITY_H
#define UTILITY_H

#include <GL/glew.h>
#include <iostream>
#include <windows.h>
#include <string>

#ifndef NDEBUG
#include "imgui.h"
#endif

namespace Utility
{

#ifndef NDEBUG
namespace Debug
{

// Usage:
//  static ExampleAppLog my_log;
//  my_log.AddLog("Hello %d world\n", 123);
//  my_log.Draw("title");
struct ImGuiLogger
{
    ImGuiTextBuffer Buf;
    ImGuiTextFilter Filter;
    ImVector<int> LineOffsets; // Index to lines offset
    bool ShowError;
    bool ShowDeprecatedBehavior;
    bool ShowUndefinedBehavior;
    bool ShowPortability;
    bool ShowPerformance;
    bool ShowMarker;
    bool ShowPushGroup;
    bool ShowPopGroup;
    bool ShowOther;
    bool ScrollToBottom;

    ImGuiLogger() : ShowError(true) {}

    void Clear();
    void AddLog(const char *fmt, ...) IM_FMTARGS(2);
    void Draw(const char *title, bool *p_open = NULL);
};

extern ImGuiLogger openGLLogger;

} // namespace Debug
#endif //NDEBUG

enum ERROR_TYPE
{
    OpenGL = 0,
    SDL,
    GLEW,
    Other
};

void APIENTRY openglCallbackFunction(GLenum source,
                                     GLenum type,
                                     GLuint id,
                                     GLenum severity,
                                     GLsizei length,
                                     const GLchar *message,
                                     const void *userParam);

void printWarning(ERROR_TYPE type, std::string msg);

void printError(ERROR_TYPE type, std::string msg);

void printInfo(ERROR_TYPE type, std::string msg);

} // namespace Utility
#endif // UTILITY_H
