use std::fmt::Debug;
use std::hash::Hash;
use async_trait::async_trait;
use crate::error::FinitomataError;
#[derive(Debug, Clone)]
pub enum TransitionResult<S, P> {
Ok(S),
OkWithPayload(S, P),
Error(FinitomataError),
}
#[async_trait]
pub trait Finitomata: Send + Sync + 'static {
type State: Clone + Send + Sync + Eq + Hash + Debug + Ord;
type Event: Clone + Send + Sync + Eq + Hash + Debug + Ord;
type Payload: Clone + Send + Sync + Debug;
async fn on_transition(
&mut self,
from: &Self::State,
event: &Self::Event,
event_payload: &Self::Payload,
state_payload: &mut Self::Payload,
) -> TransitionResult<Self::State, Self::Payload>;
async fn on_start(&mut self, _payload: &mut Self::Payload) {}
async fn on_enter(&mut self, _state: &Self::State, _payload: &mut Self::Payload) {}
async fn on_exit(&mut self, _state: &Self::State, _payload: &mut Self::Payload) {}
async fn on_failure(
&mut self,
_event: &Self::Event,
_reason: &FinitomataError,
_payload: &mut Self::Payload,
) {
}
async fn on_timer(
&mut self,
_state: &Self::State,
_payload: &mut Self::Payload,
) -> Option<(Self::Event, Self::Payload)> {
None
}
async fn on_terminate(&mut self, _payload: &mut Self::Payload) {}
}