#![allow(dead_code)]

use std::collections::HashSet;
use std::iter::IntoIterator;

use crate::misc::{MouseButton, VirtualKeyCode};

#[derive(Default)]
pub struct InputState {
    pub mouse_pos: (f32, f32),
    pub resolution: (u32, u32),
    pub close_requested: bool,
    pub key_states: HashSet<VirtualKeyCode>,
    pub button_states: HashSet<MouseButton>,
}

impl InputState {
    pub fn key_state<'a, I>(&self, codes: I) -> bool
    where
        I: IntoIterator<Item = &'a VirtualKeyCode>,
    {
        for code in codes.into_iter() {
            if self.key_states.contains(code) {
                return true;
            }
        }

        false
    }

    pub fn button_state<'a, I>(&self, buttons: I) -> bool
    where
        I: IntoIterator<Item = &'a MouseButton>,
    {
        for button in buttons.into_iter() {
            if self.button_states.contains(button) {
                return true;
            }
        }

        false
    }

    pub fn set_key_state(&mut self, code: VirtualKeyCode, value: bool) {
        if value {
            self.key_states.insert(code);
        } else {
            self.key_states.remove(&code);
        }
    }

    pub fn set_button_state(&mut self, button: MouseButton, value: bool) {
        if value {
            self.button_states.insert(button);
        } else {
            self.button_states.remove(&button);
        }
    }
}
