pub const PLAYER_EVENT_START: &str = "start";
pub const PLAYER_EVENT_JUMP: &str = "jump";
pub const PLAYER_EVENT_LAND: &str = "land";
pub const PLAYER_EVENT_FALL: &str = "fall";

/// Events which can be triggered by the player.
#[derive(Debug, Clone, Copy)]
pub enum PlayerEvent {
    // Player starts.
    Start,
    // A jump happened.
    Jump,
    // The player landed.
    Land,
    // The player fell.
    Fall,
}

impl PlayerEvent {
    // Transforms a player event as an &str.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Start => PLAYER_EVENT_START,
            Self::Jump => PLAYER_EVENT_JUMP,
            Self::Land => PLAYER_EVENT_LAND,
            Self::Fall => PLAYER_EVENT_FALL,
        }
    }
}

impl std::fmt::Display for PlayerEvent {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_fmt() {
        assert_eq!("start", format!("{}", PlayerEvent::Start));
        assert_eq!("jump", format!("{}", PlayerEvent::Jump));
        assert_eq!("land", format!("{}", PlayerEvent::Land));
        assert_eq!("fall", format!("{}", PlayerEvent::Fall));
    }
}
