use std::any::TypeId;
use std::fmt::Debug;
use std::future::Future;
use std::pin::Pin;
use std::sync::atomic::AtomicBool;
use dashmap::DashMap;
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> = DashMap<TypeId, ReactorItem<ActorEntity>>;
#[allow(dead_code)] pub enum ReactorItem<ActorEntity: Default + Send + Debug + 'static> {
Mutable(Box<FutureHandler<ActorEntity>>),
MutableFallible(Box<FutureHandlerResult<ActorEntity>>),
ReadOnly(Box<FutureHandlerReadOnly<ActorEntity>>),
ReadOnlyFallible(Box<FutureHandlerReadOnlyResult<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 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 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;