use crate::{
core::event_engine::EffectInvocation,
lib::core::fmt::{Display, Formatter, Result},
presence::event_engine::{PresenceEffect, PresenceEvent, PresenceInput},
};
#[derive(Debug)]
pub(crate) enum PresenceEffectInvocation {
Heartbeat {
input: PresenceInput,
},
Leave {
input: PresenceInput,
},
Wait {
input: PresenceInput,
},
CancelWait,
TerminateEventEngine,
}
impl EffectInvocation for PresenceEffectInvocation {
type Effect = PresenceEffect;
type Event = PresenceEvent;
fn id(&self) -> &str {
match self {
Self::Heartbeat { .. } => "HEARTBEAT",
Self::Leave { .. } => "LEAVE",
Self::Wait { .. } => "WAIT",
Self::CancelWait => "CANCEL_WAIT",
Self::TerminateEventEngine => "TERMINATE_EVENT_ENGINE",
}
}
fn is_managed(&self) -> bool {
matches!(self, Self::Wait { .. })
}
fn is_cancelling(&self) -> bool {
matches!(self, Self::CancelWait)
}
fn cancelling_effect(&self, effect: &Self::Effect) -> bool {
matches!(effect, PresenceEffect::Wait { .. }) && matches!(self, Self::CancelWait { .. })
}
fn is_terminating(&self) -> bool {
matches!(self, Self::TerminateEventEngine)
}
}
impl Display for PresenceEffectInvocation {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::Heartbeat { .. } => write!(f, "HEARTBEAT"),
Self::Leave { .. } => write!(f, "LEAVE"),
Self::Wait { .. } => write!(f, "WAIT"),
Self::CancelWait => write!(f, "CANCEL_WAIT"),
Self::TerminateEventEngine => write!(f, "TERMINATE_EVENT_ENGINE"),
}
}
}