#pragma once
#include <SDL2/SDL.h>
#include <cstdint>

namespace quokka_gfx
{
//------------------------------------------------------------
class Color
{
  public:
  constexpr Color()                  = default;     // Default constructor
  virtual ~Color()                   = default;     // Default destructor
  Color(const Color &obj)            = default;     // Copy constructor
  Color(Color &&obj)                 = default;     // Move constructor
  Color &operator=(const Color &obj) = default;     // Copy assignment operator
  Color &operator=(Color &&obj)      = default;     // Move assignment operator

  constexpr explicit Color(uint32_t color = 0xFFFFFFFF);     // Constructor
  constexpr explicit Color(uint8_t red   = 255,              // Constructor
                           uint8_t green = 255,
                           uint8_t blue  = 255,
                           uint8_t alpha = 255);

  [[nodiscard]] uint32_t operator()() const;     // Returns the color as a single uint32_t in ARGB format
  [[nodiscard]] uint8_t  r() const;              // Returns the red component
  [[nodiscard]] uint8_t  g() const;              // Returns the green component
  [[nodiscard]] uint8_t  b() const;              // Returns the blue component
  [[nodiscard]] uint8_t  a() const;              // Returns the alpha component

  protected:
  uint32_t m_color = 0xFFFFFFFF;     // Color value in ARGB format for fast comparisons and hashing
};
//------------------------------------------------------------
/* Constructor */
inline constexpr Color::Color(const uint32_t color)
{
  m_color = color;
}
//------------------------------------------------------------
/* Constructor */
inline constexpr Color::Color(const uint8_t red, const uint8_t green, const uint8_t blue, const uint8_t alpha)
{
  m_color = (static_cast<uint32_t>(alpha) << 24) |
            (static_cast<uint32_t>(red) << 16) |
            (static_cast<uint32_t>(green) << 8) |
            static_cast<uint32_t>(blue);
}
//------------------------------------------------------------
/* Returns the color as a single uint32_t in ARGB format */
inline uint32_t Color::operator()() const
{
  return m_color;
}
//------------------------------------------------------------
/* Returns the red component */
inline uint8_t Color::r() const
{
  return (m_color >> 16) & 0xFF;
}
//------------------------------------------------------------
/* Returns the green component */
inline uint8_t Color::g() const
{
  return (m_color >> 8) & 0xFF;
}
//------------------------------------------------------------
/* Returns the blue component */
inline uint8_t Color::b() const
{
  return m_color & 0xFF;
}
//------------------------------------------------------------
/* Returns the alpha component */
inline uint8_t Color::a() const
{
  return (m_color >> 24) & 0xFF;
}
//------------------------------------------------------------

/* --- */

//------------------------------------------------------------
inline constexpr Color White{ 255, 255, 255, 255 };
inline constexpr Color Black{ 0, 0, 0, 255 };
inline constexpr Color Red{ 255, 0, 0, 255 };
inline constexpr Color Green{ 0, 255, 0, 255 };
inline constexpr Color Blue{ 0, 0, 255, 255 };
inline constexpr Color Yellow{ 255, 255, 0, 255 };
inline constexpr Color Gray{ 128, 128, 128, 255 };
inline constexpr Color DarkGray{ 64, 64, 64, 255 };
//------------------------------------------------------------
}     // namespace quokka_gfx
