use acton_ern::{Ern, ErnParser};
use crate::common::{BrokerRef, ParentRef};
use crate::traits::AgentHandleInterface;
#[derive(Default, Debug, Clone)]
pub struct AgentConfig {
id: Ern,
pub(crate) broker: Option<BrokerRef>,
parent: Option<ParentRef>,
}
impl AgentConfig {
pub fn new(
id: Ern,
parent: Option<ParentRef>,
broker: Option<BrokerRef>,
) -> anyhow::Result<AgentConfig> {
if let Some(parent_ref) = parent { let parent_id = ErnParser::new(parent_ref.id().to_string()).parse()?;
let child_id = parent_id + id;
Ok(AgentConfig {
id: child_id,
broker,
parent: Some(parent_ref),
})
} else {
Ok(AgentConfig {
id,
broker,
parent, })
}
}
pub fn new_with_name(
name: impl Into<String>,
) -> anyhow::Result<AgentConfig> {
Self::new(Ern::with_root(name.into())?, None, None)
}
#[inline]
pub(crate) fn id(&self) -> Ern {
self.id.clone()
}
#[inline]
pub(crate) fn get_broker(&self) -> &Option<BrokerRef> {
&self.broker
}
#[inline]
pub(crate) fn parent(&self) -> &Option<ParentRef> {
&self.parent
}
}