using UnityEngine;

namespace RebootKit.Engine.Extensions {
    public static class ColorEx {
        public static Color With(this Color color, float? red = null, float? green = null, float? blue = null, float? alpha = null) {
            return new Color(red ?? color.r,
                             green ?? color.g,
                             blue ?? color.b,
                             alpha ?? color.a);
        }

        public static string ToHexRGBA(this Color color) {
            return $"#{ColorUtility.ToHtmlStringRGBA(color)}";
        }

        public static string ToHexRGB(this Color color) {
            return $"#{ColorUtility.ToHtmlStringRGB(color)}";
        }

        public static Color Clamp01(this Color color) {
            return new Color {
                r = Mathf.Clamp01(color.r),
                g = Mathf.Clamp01(color.g),
                b = Mathf.Clamp01(color.b),
                a = Mathf.Clamp01(color.a)
            };
        }
    }
}