namespace SharpChat;

public readonly record struct ColourInheritable(ColourRgb? Rgb) {
    public static readonly ColourInheritable None = new(null);
    public override string ToString() => Rgb.HasValue ? Rgb.Value.ToString() : "inherit";

    public bool Inherits => !Rgb.HasValue;

    public static ColourInheritable FromRaw(int? raw) => raw is null ? None : new(new ColourRgb(raw.Value));
    public static ColourInheritable FromRgb(byte red, byte green, byte blue) => new(ColourRgb.FromRgb(red, green, blue));

    // these should go Away
    private const int MSZ_INHERIT = 0x40000000;
    public int ToMisuzu() => Rgb.HasValue ? Rgb.Value.Raw : MSZ_INHERIT;
    public static ColourInheritable FromMisuzu(int msz) => (msz & MSZ_INHERIT) > 0 ? None : new(new ColourRgb(msz & 0xFFFFFF));
}