/**
 * @file Color.h
 * @author apio (cloudapio.eu)
 * @brief RGBA colors.
 *
 * @copyright Copyright (c) 2023, the Luna authors.
 *
 */

#pragma once
#include <luna/Types.h>

namespace ui
{
    /**
     * @brief A 32-bit ARGB color.
     */
    struct Color
    {
        union {
            u32 raw;
            u8 colors[4];
        };

        /**
         * @brief Return the blue value of this color.
         *
         * @return constexpr u8 The blue value.
         */
        constexpr u8 red() const
        {
            return colors[2];
        }

        /**
         * @brief Return the green value of this color.
         *
         * @return constexpr u8 The green value.
         */
        constexpr u8 green() const
        {
            return colors[1];
        }

        /**
         * @brief Return the blue value of this color.
         *
         * @return constexpr u8 The blue value.
         */
        constexpr u8 blue() const
        {
            return colors[0];
        }

        /**
         * @brief Return the alpha value of this color.
         *
         * @return constexpr u8 The alpha value.
         */
        constexpr u8 alpha() const
        {
            return colors[3];
        }

        /**
         * @brief Construct a new color from a 32-bit ARGB integer.
         *
         * @param raw The integer representing the color.
         * @return constexpr Color The new color.
         */
        static constexpr Color from_u32(u32 raw)
        {
            return Color { .raw = raw };
        }

        /**
         * @brief Construct a new color from its separate RGBA values (from 0 to 255).
         *
         * @param red The red value.
         * @param green The green value.
         * @param blue The blue value.
         * @param alpha The alpha value.
         * @return constexpr Color The new color.
         */
        static constexpr Color from_rgba(u8 red, u8 green, u8 blue, u8 alpha)
        {
            return Color { .colors = { blue, green, red, alpha } };
        }

        /**
         * @brief Construct a new color from its separate RGB values (from 0 to 255).
         *
         * @param red The red value.
         * @param green The green value.
         * @param blue The blue value.
         * @return constexpr Color The new color.
         */
        static constexpr Color from_rgb(u8 red, u8 green, u8 blue)
        {
            return from_rgba(red, green, blue, 0xff);
        }
    };

    static constexpr Color WHITE = Color::from_rgb(0xff, 0xff, 0xff);
    static constexpr Color BLACK = Color::from_rgb(0x00, 0x00, 0x00);
    static constexpr Color GRAY = Color::from_rgb(0x80, 0x80, 0x80);

    static constexpr Color BLUE = Color::from_rgb(0x00, 0x00, 0xff);
    static constexpr Color GREEN = Color::from_rgb(0x00, 0xff, 0x00);
    static constexpr Color RED = Color::from_rgb(0xff, 0x00, 0x00);

    static constexpr Color CYAN = Color::from_rgb(0x00, 0xff, 0xff);
};