use holochain_client_instrumented::prelude::AppWebsocket;
use holochain_types::prelude::{CellId, RoleName};
use std::fmt::Debug;
use std::{collections::HashMap, net::SocketAddr};
use wind_tunnel_runner::prelude::UserValuesConstraint;
use crate::holochain_runner::{HolochainConfigBuilder, HolochainRunner};
#[derive(Debug, Default)]
pub struct DefaultScenarioValues {
pub values: HashMap<String, String>,
}
impl UserValuesConstraint for DefaultScenarioValues {}
#[derive(Default, Debug)]
pub struct HolochainAgentContext<T: UserValuesConstraint = DefaultScenarioValues> {
pub(crate) installed_app_id: Option<String>,
pub(crate) cell_role_name: Option<RoleName>,
pub(crate) cell_id: Option<CellId>,
pub(crate) app_client: Option<AppWebsocket>,
pub(crate) app_ws_url: Option<SocketAddr>,
pub(crate) admin_ws_url: Option<SocketAddr>,
pub(crate) holochain_config: Option<HolochainConfigBuilder>,
pub(crate) holochain_runner: Option<HolochainRunner>,
pub scenario_values: T,
}
impl<T: UserValuesConstraint> UserValuesConstraint for HolochainAgentContext<T> {}
impl<T: UserValuesConstraint> HolochainAgentContext<T> {
pub fn installed_app_id(&self) -> anyhow::Result<String> {
self.installed_app_id.clone().ok_or_else(|| anyhow::anyhow!("installed_app_id is not set, did you forget to call `install_app` in your agent_setup?"))
}
pub fn cell_id(&self) -> CellId {
self.cell_id
.clone()
.expect("cell_id is not set, did you forget to call `install_app` in your agent_setup?")
}
pub fn cell_role_name(&self) -> RoleName {
self.cell_role_name.clone().expect(
"cell_role_name is not set, did you forget to call `install_app` in your agent_setup?",
)
}
pub fn app_client(&self) -> AppWebsocket {
self.app_client.clone().expect(
"app_client is not set, did you forget to call `install_app` in your agent_setup?",
)
}
pub fn admin_ws_url(&self) -> SocketAddr {
self.admin_ws_url.expect(
"admin_ws_url is not set, did you forget to call `configure_admin_ws_url` in your agent_setup?",
)
}
pub fn app_ws_url(&self) -> SocketAddr {
self.app_ws_url.expect(
"app_ws_url is not set, did you forget to call `configure_app_ws_url` in your agent_setup?",
)
}
pub fn holochain_config_mut(&mut self) -> &mut HolochainConfigBuilder {
self.holochain_config.get_or_insert_default()
}
pub(crate) fn take_holochain_config(&mut self) -> HolochainConfigBuilder {
self.holochain_config.take().unwrap_or_default()
}
}