use winit::{event::MouseButton, keyboard::KeyCode};

/// Fired when the window is resized.
pub struct Resized {
    /// The window's current physical width.
    pub width: u32,

    /// The window's current physical height.
    pub height: u32,
}

impl Resized {
    /// Initializes [`self`] with a width and height.
    pub const fn from_size(width: u32, height: u32) -> Self {
        Self { height, width }
    }
}

/// Fired when a key is pressed.
///
/// List of keys isn't final.
pub enum Key {
    Escape,
    Tab,
    ShiftLeft,
    ShiftRight,
    ControlLeft,
    ControlRight,
    Space,
    Q,
    W,
    E,
    R,
    T,
    Y,
    U,
    I,
    O,
    P,
    A,
    S,
    D,
    F,
    G,
    H,
    J,
    K,
    L,
    Z,
    X,
    C,
    V,
    B,
    N,
    M,
    Unknown,
}

impl From<KeyCode> for Key {
    fn from(code: KeyCode) -> Self {
        match code {
            KeyCode::Escape => Self::Escape,
            KeyCode::Tab => Self::Tab,
            KeyCode::ShiftLeft => Self::ShiftLeft,
            KeyCode::ShiftRight => Self::ShiftRight,
            KeyCode::ControlLeft => Self::ControlLeft,
            KeyCode::ControlRight => Self::ControlRight,
            KeyCode::Space => Self::Space,
            KeyCode::KeyQ => Key::Q,
            KeyCode::KeyW => Key::W,
            KeyCode::KeyE => Key::E,
            KeyCode::KeyR => Key::R,
            KeyCode::KeyT => Key::T,
            KeyCode::KeyY => Key::Y,
            KeyCode::KeyU => Key::U,
            KeyCode::KeyI => Key::I,
            KeyCode::KeyO => Key::O,
            KeyCode::KeyP => Key::P,
            KeyCode::KeyA => Key::A,
            KeyCode::KeyS => Key::S,
            KeyCode::KeyD => Key::D,
            KeyCode::KeyF => Key::F,
            KeyCode::KeyG => Key::G,
            KeyCode::KeyH => Key::H,
            KeyCode::KeyJ => Key::J,
            KeyCode::KeyK => Key::K,
            KeyCode::KeyL => Key::L,
            KeyCode::KeyZ => Key::Z,
            KeyCode::KeyX => Key::X,
            KeyCode::KeyC => Key::C,
            KeyCode::KeyV => Key::V,
            KeyCode::KeyB => Key::B,
            KeyCode::KeyN => Key::N,
            KeyCode::KeyM => Key::M,
            _ => Key::Unknown,
        }
    }
}

/// Fired when theres mouse input.
pub struct MouseMotion {
    pub delta_x: f64,
    pub delta_y: f64,
}

impl MouseMotion {
    /// Initializes [`self`] via mouse position deltas.
    pub const fn from_delta(delta_x: f64, delta_y: f64) -> Self {
        Self { delta_x, delta_y }
    }
}

/// Mouse buttons.
pub enum Mouse {
    Left,
    Right,
    Middle,
    Forward,
    Back,
    Unknown,
}

impl From<MouseButton> for Mouse {
    fn from(button: MouseButton) -> Self {
        match button {
            MouseButton::Left => Mouse::Left,
            MouseButton::Right => Mouse::Right,
            MouseButton::Back => Mouse::Back,
            MouseButton::Forward => Mouse::Forward,
            MouseButton::Middle => Mouse::Middle,
            _ => Mouse::Unknown,
        }
    }
}
