namespace RioJoy.Core.Protocol;

/// <summary>Flash mode for a lighted button (lamp-state bits 0–1).</summary>
public enum LampFlash : byte
{
    Solid = 0,
    FlashSlow = 1,
    FlashMed = 2,
    FlashFast = 3,
}

/// <summary>Lamp brightness "field 1" (bits 2–3).</summary>
public enum LampField1 : byte
{
    Off = 0x00,
    Dim = 0x04,
    Bright = 0x0C,
}

/// <summary>Lamp brightness "field 2" (bits 4–5).</summary>
public enum LampField2 : byte
{
    Off = 0x00,
    Dim = 0x10,
    Bright = 0x30,
}

/// <summary>
/// The <c>state</c> byte of a <see cref="RioCommand.LampRequest"/>, composed of
/// a flash mode plus two brightness fields. Port of <c>enum LampState</c>
/// (riovjoy2.cpp#L213); see docs/PROTOCOL.md §3.
/// </summary>
public static class RioLampState
{
    /// <summary>Compose a lamp-state byte from its flash + brightness parts.</summary>
    public static byte Compose(LampFlash flash, LampField1 field1, LampField2 field2) =>
        (byte)((byte)flash + (byte)field1 + (byte)field2);

    /// <summary>Lamp off: <c>SolidOff</c> (0x00).</summary>
    public static readonly byte SolidOff =
        Compose(LampFlash.Solid, LampField1.Off, LampField2.Off);

    /// <summary>Dim solid: <c>SolidDim</c> (0x14). Used for idle/released lamps.</summary>
    public static readonly byte SolidDim =
        Compose(LampFlash.Solid, LampField1.Dim, LampField2.Dim);

    /// <summary>Bright solid: <c>SolidBright</c> (0x3C). Used for pressed lamps.</summary>
    public static readonly byte SolidBright =
        Compose(LampFlash.Solid, LampField1.Bright, LampField2.Bright);
}
