use bone_app::InputDispatched;
use std::sync::Arc;
use winit::window::Window;

const KICKS_AFTER_INTERACTION: u8 = 2;

pub struct Scheduler {
    window: Arc<Window>,
    kicks: u8,
}

impl Scheduler {
    pub fn new(window: Arc<Window>) -> Self {
        Self { window, kicks: 0 }
    }

    pub fn schedule(&mut self, _ack: InputDispatched) {
        self.kicks = self.kicks.max(KICKS_AFTER_INTERACTION);
        self.window.request_redraw();
    }

    pub fn kick(&mut self) {
        self.kicks = self.kicks.max(KICKS_AFTER_INTERACTION);
    }

    pub fn consume_kick(&mut self) {
        if self.kicks > 0 {
            self.kicks -= 1;
            self.window.request_redraw();
        }
    }

    #[must_use]
    pub fn window(&self) -> &Window {
        &self.window
    }
}
