#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Colour {
    ARGB(u8, u8, u8, u8),
    RGB(u8, u8, u8),
    HexARGB(u32),
    Black = 0x000000FF,
    Blue = 0x0000FFFF,
    Green = 0x00FF00FF,
    Cyan = 0x00FFFFFF,
    Red = 0xFF0000FF,
    Magenta = 0xFF00FFFF,
    Yellow = 0xFFFF00FF,
    White = 0xFFFFFFFF,
}

#[allow(clippy::use_self)]
impl From<Colour> for u32 {
    fn from(val: Colour) -> Self {
        match val {
            Colour::ARGB(a, r, g, b) => {
                (a as u32) << 24
                    | (r as u32) << 16
                    | (g as u32) << 8
                    | (b as u32)
            }
            Colour::RGB(r, g, b) => {
                ((r as u32) << 16) | (g as u32) << 8 | (b as u32)
            }
            Colour::HexARGB(hex) => hex,
            Colour::Black => 0xFF000000,
            Colour::Blue => 0xFF0000FF,
            Colour::Green => 0xFF00FF00,
            Colour::Cyan => 0xFF00FFFF,
            Colour::Red => 0xFFFF0000,
            Colour::Magenta => 0xFFFF00FF,
            Colour::Yellow => 0xFFFFFF00,
            Colour::White => 0xFFFFFFFF,
        }
    }
}

impl core::fmt::Display for Colour {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::ARGB(r, g, b, a) => {
                write!(f, "RGBA(#{:x}{:x}{:x}{:x})", r, g, b, a)
            }
            Self::RGB(r, g, b) => write!(f, "RGB(#{:x}{:x}{:x})", r, g, b),
            Self::HexARGB(hex) => write!(f, "Hex(#{:x})", hex),
            Self::Black => write!(f, "Black"),
            Self::Blue => write!(f, "Blue"),
            Self::Green => write!(f, "Green"),
            Self::Cyan => write!(f, "Cyan"),
            Self::Red => write!(f, "Red"),
            Self::Magenta => write!(f, "Magenta"),
            Self::Yellow => write!(f, "Yellow"),
            Self::White => write!(f, "White"),
        }
    }
}
