use std::any::TypeId;
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
use std::sync::atomic::AtomicBool;
use std::collections::HashMap;
use tokio::sync::mpsc::Sender;
use crate::actor::{ManagedActor, Started};
use crate::common::ActorHandle;
use crate::message::Envelope;
use crate::traits::ActonMessageReply;
pub type ReactorMap<ActorEntity> = HashMap<TypeId, ReactorItem<ActorEntity>>;
#[allow(dead_code)] pub enum ReactorItem<ActorEntity: Default + Send + Debug + 'static> {
Mutable(Box<FutureHandler<ActorEntity>>),
MutableFallible(Box<FutureHandlerResult<ActorEntity>>),
MutableSync(Box<SyncHandler<ActorEntity>>),
ReadOnly(Box<FutureHandlerReadOnly<ActorEntity>>),
ReadOnlyFallible(Box<FutureHandlerReadOnlyResult<ActorEntity>>),
ReadOnlySync(Box<SyncHandlerReadOnly<ActorEntity>>),
}
pub type FutureHandler<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a mut ManagedActor<Started, ManagedEntity>, &'b mut Envelope, ) -> FutureBox + Send
+ Sync
+ 'static;
pub type FutureHandlerResult<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a mut ManagedActor<Started, ManagedEntity>,
&'b mut Envelope,
) -> FutureBoxResult
+ Send
+ Sync
+ 'static;
pub type FutureHandlerReadOnly<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a ManagedActor<Started, ManagedEntity>, &'b mut Envelope,
) -> FutureBoxReadOnly
+ Send
+ Sync
+ 'static;
pub type FutureHandlerReadOnlyResult<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a ManagedActor<Started, ManagedEntity>, &'b mut Envelope,
) -> FutureBoxReadOnlyResult
+ Send
+ Sync
+ 'static;
pub type SyncHandler<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a mut ManagedActor<Started, ManagedEntity>,
&'b mut Envelope,
) + Send
+ Sync
+ 'static;
pub type SyncHandlerReadOnly<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a ManagedActor<Started, ManagedEntity>,
&'b mut Envelope,
) + Send
+ Sync
+ 'static;
pub type ErrorHandler<ManagedEntity> = dyn for<'a, 'b> Fn(
&'a mut ManagedActor<Started, ManagedEntity>,
&'b mut Envelope,
&(dyn std::error::Error + 'static),
) -> FutureBox
+ Send
+ Sync
+ 'static;
pub type FutureBox = Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
pub type FutureBoxReadOnly = Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
pub type FutureBoxResult = Pin<
Box<
dyn Future<
Output = Result<
Box<dyn ActonMessageReply + Send>,
(Box<dyn std::error::Error + Send + Sync>, TypeId),
>,
> + Send
+ Sync
+ 'static,
>,
>;
pub type FutureBoxReadOnlyResult = Pin<
Box<
dyn Future<
Output = Result<
Box<dyn ActonMessageReply + Send>,
(Box<dyn std::error::Error + Send + Sync>, TypeId),
>,
> + Send
+ Sync
+ 'static,
>,
>;
pub struct ReadOnlyHandlerError {
pub envelope: Envelope,
pub message_type_id: TypeId,
pub error_type_id: TypeId,
pub error: Box<dyn std::error::Error + Send + Sync>,
}
pub type FutureBoxReadOnlyOutcome =
Pin<Box<dyn Future<Output = Option<ReadOnlyHandlerError>> + Send + Sync + 'static>>;
pub type ActorSender = Sender<Envelope>;
pub type HaltSignal = AtomicBool;
pub type AsyncLifecycleHandler<ManagedEntity> =
Option<Box<dyn Fn(&ManagedActor<Started, ManagedEntity>) -> FutureBox + Send + Sync + 'static>>;
pub type BrokerRef = ActorHandle;
pub type ParentRef = ActorHandle;