use std::{collections::HashMap, sync::Arc};
use anyhow::Result;
use hash_map_id::HashMapId;
use tokio::sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
Mutex, RwLock,
};
use wasmtime::Linker;
use crate::{
config::ProcessConfig,
mailbox::MessageMailbox,
runtimes::wasmtime::{WasmtimeCompiledModule, WasmtimeRuntime},
Signal,
};
pub type ConfigResources<T> = HashMapId<T>;
pub type SignalSender = UnboundedSender<Signal>;
pub type SignalReceiver = Arc<Mutex<UnboundedReceiver<Signal>>>;
pub trait ProcessState: Sized {
type Config: ProcessConfig + Default + Send + Sync;
fn new_state(
&self,
module: Arc<WasmtimeCompiledModule<Self>>,
config: Arc<Self::Config>,
) -> Result<Self>;
fn register(linker: &mut Linker<Self>) -> Result<()>;
fn initialize(&mut self);
fn is_initialized(&self) -> bool;
fn runtime(&self) -> &WasmtimeRuntime;
fn module(&self) -> &Arc<WasmtimeCompiledModule<Self>>;
fn config(&self) -> &Arc<Self::Config>;
fn id(&self) -> u64;
fn signal_mailbox(&self) -> &(SignalSender, SignalReceiver);
fn message_mailbox(&self) -> &MessageMailbox;
fn config_resources(&self) -> &ConfigResources<Self::Config>;
fn config_resources_mut(&mut self) -> &mut ConfigResources<Self::Config>;
fn registry(&self) -> &Arc<RwLock<HashMap<String, (u64, u64)>>>;
}