using UnityEngine;

namespace pdinklag
{
    /// <summary>
    /// Extension methods for <see cref="Color"/>.
    /// </summary>
    public static class ColorExtensions
    {
        public static readonly Color Orange = new(1.0f, 0.5f, 0.0f);
        public static readonly Color LightBlue = new(0.0f, 0.5f, 1.0f);
        public static readonly Color Violet = new(0.5f, 0.0f, 1.0f);

        /// <summary>
        /// Returns the color with the specified alpha value.
        /// </summary>
        /// <param name="color">the color</param>
        /// <param name="a">the alpha value to use</param>
        /// <returns>the color with the specified alpha value</returns>
        public static Color WithAlpha(this Color color, float a)
        {
            return new Color(color.r, color.g, color.b, a);
        }

        /// <summary>
        /// Brightens the color by increasing its components.
        /// </summary>
        /// <param name="color">the input color</param>
        /// <param name="amount">the amount to brighten or darken</param>
        /// <returns>the resulting color</returns>
        public static Color Brighter(this Color color, float amount)
        {
            color.r = Mathf.Clamp01(color.r + amount);
            color.g = Mathf.Clamp01(color.g + amount);
            color.b = Mathf.Clamp01(color.b + amount);
            return color;
        }

        /// <summary>
        /// Darkens the color by decreasing its value component.
        /// </summary>
        /// <param name="color">the input color</param>
        /// <param name="amount">the amount to darken</param>
        /// <returns>the resulting color</returns>
        public static Color Darker(this Color color, float amount)
        {
            return Brighter(color, -amount);
        }
    }
}
