#pragma once

#include "Block.h"

#include "string"


/**
 * A color encoded in RGB
 */
struct Color {
    unsigned char red;   // the red component of the color
    unsigned char green; // the green component of the color
    unsigned char blue;  // the blue component of the color
};


static const Color EMPTY_BLOCK_COLOR = {255, 255, 255}; // color of an empty block
static const Color BLOCKS_COLOR[] = {                   // color for each block type
    EMPTY_BLOCK_COLOR, // NOTHING
    EMPTY_BLOCK_COLOR, // OUT_OF_BOUNDS
    {150, 150, 150},   // GARBAGE
    {150, 0, 255},     // PURPLE
    {255, 150, 0},     // ORANGE
    {0, 255, 255},     // CYAN
    {255, 0, 200},     // PINK
    {255, 255, 0},     // YELLOW
    {255, 0, 0},       // RED
    {0, 100, 255},     // BLUE
    {0, 255, 0}        // GREEN
};

/**
 * Translates the color into a color code to change the console's color
 * @return A string to print in the console
 */
inline std::string getConsoleColorCode(const Color& color) {
    return "\033[38;2;" + std::to_string(color.red) + ";" + std::to_string(color.green) + ";" + std::to_string(color.blue) + "m";
}

/**
 * Translates the color into a color code to change the console's color
 * @return A string to print in the console
 */
inline std::string getConsoleColorCode(const Block block) {
    return getConsoleColorCode(BLOCKS_COLOR[block]);
}

/**
 * Gets a color code to reset the console's color
 * @return A string to print in the console
 */
inline std::string getResetConsoleColorCode() {
    return getConsoleColorCode(EMPTY_BLOCK_COLOR);
}
