// Implementation of ConsoleColor for Windows.
#ifdef _WIN32

#include <windows.h>

#include <Utilities/ConsoleColor.hpp>
#include <Utilities/Utilities.hpp>

WORD getAttributeForColor(ConsoleColor color)
{
    switch (color)
    {
    case ConsoleColor::Black: return 0;
    case ConsoleColor::Red: return 4;
    case ConsoleColor::Green: return 2;
    case ConsoleColor::Yellow: return 6;
    case ConsoleColor::Blue: return 1;
    case ConsoleColor::Magenta: return 5;
    case ConsoleColor::Cyan: return 3;
    case ConsoleColor::White: return 7;
    case ConsoleColor::Reset: return 7;
    default: crash("Invalid console color!");
    }
}

std::ostream& operator<<(std::ostream &os, ConsoleColor color)
{
    os.flush();

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, getAttributeForColor(color));

    return os;
}

#endif /* _WIN32 */