use std::{collections::BTreeMap, fmt::Debug, hash::Hash};
use peace_core::Profile;
use peace_params::ParamsSpecs;
use peace_resources::{
paths::{FlowDir, PeaceAppDir, PeaceDir, ProfileDir, ProfileHistoryDir, WorkspaceDir},
resources::ts::SetUp,
states::StatesSaved,
Resources,
};
use peace_rt_model::{
params::{
FlowParams, KeyKnown, KeyMaybe, ParamsKeys, ParamsKeysImpl, ParamsTypeRegs, ProfileParams,
WorkspaceParams,
},
Flow, ItemParamsTypeReg, ParamsSpecsTypeReg, StatesTypeReg, Workspace,
};
use serde::{de::DeserializeOwned, Serialize};
#[derive(Debug)]
pub struct MultiProfileSingleFlow<'ctx, E, O, PKeys, TS>
where
PKeys: ParamsKeys + 'static,
{
output: &'ctx mut O,
workspace: &'ctx Workspace,
profiles: Vec<Profile>,
profile_dirs: BTreeMap<Profile, ProfileDir>,
profile_history_dirs: BTreeMap<Profile, ProfileHistoryDir>,
flow: &'ctx Flow<E>,
flow_dirs: BTreeMap<Profile, FlowDir>,
params_type_regs: ParamsTypeRegs<PKeys>,
workspace_params: WorkspaceParams<<PKeys::WorkspaceParamsKMaybe as KeyMaybe>::Key>,
profile_to_profile_params:
BTreeMap<Profile, ProfileParams<<PKeys::ProfileParamsKMaybe as KeyMaybe>::Key>>,
profile_to_flow_params:
BTreeMap<Profile, FlowParams<<PKeys::FlowParamsKMaybe as KeyMaybe>::Key>>,
profile_to_states_saved: BTreeMap<Profile, Option<StatesSaved>>,
item_params_type_reg: ItemParamsTypeReg,
params_specs_type_reg: ParamsSpecsTypeReg,
profile_to_params_specs: BTreeMap<Profile, Option<ParamsSpecs>>,
states_type_reg: StatesTypeReg,
resources: Resources<TS>,
}
#[derive(Debug)]
pub struct MultiProfileSingleFlowView<'view, E, O, PKeys, TS>
where
PKeys: ParamsKeys + 'static,
{
pub output: &'view mut O,
pub workspace: &'view Workspace,
pub profiles: &'view [Profile],
pub profile_dirs: &'view BTreeMap<Profile, ProfileDir>,
pub profile_history_dirs: &'view BTreeMap<Profile, ProfileHistoryDir>,
pub flow: &'view Flow<E>,
pub flow_dirs: &'view BTreeMap<Profile, FlowDir>,
pub params_type_regs: &'view ParamsTypeRegs<PKeys>,
pub workspace_params: &'view WorkspaceParams<<PKeys::WorkspaceParamsKMaybe as KeyMaybe>::Key>,
pub profile_to_profile_params:
&'view BTreeMap<Profile, ProfileParams<<PKeys::ProfileParamsKMaybe as KeyMaybe>::Key>>,
pub profile_to_flow_params:
&'view BTreeMap<Profile, FlowParams<<PKeys::FlowParamsKMaybe as KeyMaybe>::Key>>,
pub profile_to_states_saved: &'view BTreeMap<Profile, Option<StatesSaved>>,
pub item_params_type_reg: &'view ItemParamsTypeReg,
pub params_specs_type_reg: &'view ParamsSpecsTypeReg,
pub profile_to_params_specs: &'view BTreeMap<Profile, Option<ParamsSpecs>>,
pub states_type_reg: &'view StatesTypeReg,
pub resources: &'view mut Resources<TS>,
}
impl<'ctx, E, O, PKeys> MultiProfileSingleFlow<'ctx, E, O, PKeys, SetUp>
where
PKeys: ParamsKeys + 'static,
{
#[allow(clippy::too_many_arguments)] pub(crate) fn new(
output: &'ctx mut O,
workspace: &'ctx Workspace,
profiles: Vec<Profile>,
profile_dirs: BTreeMap<Profile, ProfileDir>,
profile_history_dirs: BTreeMap<Profile, ProfileHistoryDir>,
flow: &'ctx Flow<E>,
flow_dirs: BTreeMap<Profile, FlowDir>,
params_type_regs: ParamsTypeRegs<PKeys>,
workspace_params: WorkspaceParams<<PKeys::WorkspaceParamsKMaybe as KeyMaybe>::Key>,
profile_to_profile_params: BTreeMap<
Profile,
ProfileParams<<PKeys::ProfileParamsKMaybe as KeyMaybe>::Key>,
>,
profile_to_flow_params: BTreeMap<
Profile,
FlowParams<<PKeys::FlowParamsKMaybe as KeyMaybe>::Key>,
>,
profile_to_states_saved: BTreeMap<Profile, Option<StatesSaved>>,
item_params_type_reg: ItemParamsTypeReg,
params_specs_type_reg: ParamsSpecsTypeReg,
profile_to_params_specs: BTreeMap<Profile, Option<ParamsSpecs>>,
states_type_reg: StatesTypeReg,
resources: Resources<SetUp>,
) -> Self {
Self {
output,
workspace,
profiles,
profile_dirs,
profile_history_dirs,
flow,
flow_dirs,
params_type_regs,
workspace_params,
profile_to_profile_params,
profile_to_flow_params,
profile_to_states_saved,
item_params_type_reg,
params_specs_type_reg,
profile_to_params_specs,
states_type_reg,
resources,
}
}
}
impl<'ctx, E, O, PKeys, TS> MultiProfileSingleFlow<'ctx, E, O, PKeys, TS>
where
PKeys: ParamsKeys + 'static,
{
pub fn view(&mut self) -> MultiProfileSingleFlowView<'_, E, O, PKeys, TS> {
let Self {
output,
workspace,
profiles,
profile_dirs,
profile_history_dirs,
flow,
flow_dirs,
params_type_regs,
workspace_params,
profile_to_profile_params,
profile_to_flow_params,
profile_to_states_saved,
item_params_type_reg,
params_specs_type_reg,
profile_to_params_specs,
states_type_reg,
resources,
} = self;
MultiProfileSingleFlowView {
output,
workspace,
profiles,
profile_dirs,
profile_history_dirs,
flow,
flow_dirs,
params_type_regs,
workspace_params,
profile_to_profile_params,
profile_to_flow_params,
profile_to_states_saved,
item_params_type_reg,
params_specs_type_reg,
profile_to_params_specs,
states_type_reg,
resources,
}
}
pub fn output(&self) -> &O {
self.output
}
pub fn output_mut(&mut self) -> &mut O {
self.output
}
pub fn workspace(&self) -> &Workspace {
self.workspace
}
pub fn workspace_dir(&self) -> &WorkspaceDir {
self.workspace.dirs().workspace_dir()
}
pub fn peace_dir(&self) -> &PeaceDir {
self.workspace.dirs().peace_dir()
}
pub fn peace_app_dir(&self) -> &PeaceAppDir {
self.workspace.dirs().peace_app_dir()
}
pub fn profiles(&self) -> &[Profile] {
self.profiles.as_ref()
}
pub fn profile_dirs(&self) -> &BTreeMap<Profile, ProfileDir> {
&self.profile_dirs
}
pub fn profile_history_dirs(&self) -> &BTreeMap<Profile, ProfileHistoryDir> {
&self.profile_history_dirs
}
pub fn flow(&self) -> &Flow<E> {
self.flow
}
pub fn flow_dirs(&self) -> &BTreeMap<Profile, FlowDir> {
&self.flow_dirs
}
pub fn params_type_regs(&self) -> &ParamsTypeRegs<PKeys> {
&self.params_type_regs
}
pub fn profile_to_states_saved(&self) -> &BTreeMap<Profile, Option<StatesSaved>> {
&self.profile_to_states_saved
}
pub fn item_params_type_reg(&self) -> &ItemParamsTypeReg {
&self.item_params_type_reg
}
pub fn params_specs_type_reg(&self) -> &ParamsSpecsTypeReg {
&self.params_specs_type_reg
}
pub fn profile_to_params_specs(&self) -> &BTreeMap<Profile, Option<ParamsSpecs>> {
&self.profile_to_params_specs
}
pub fn states_type_reg(&self) -> &StatesTypeReg {
&self.states_type_reg
}
pub fn resources(&self) -> &Resources<TS> {
&self.resources
}
pub fn resources_mut(&mut self) -> &mut Resources<TS> {
&mut self.resources
}
}
impl<'ctx, E, O, WorkspaceParamsK, ProfileParamsKMaybe, FlowParamsKMaybe, TS>
MultiProfileSingleFlow<
'ctx,
E,
O,
ParamsKeysImpl<KeyKnown<WorkspaceParamsK>, ProfileParamsKMaybe, FlowParamsKMaybe>,
TS,
>
where
WorkspaceParamsK:
Clone + Debug + Eq + Hash + DeserializeOwned + Serialize + Send + Sync + 'static,
ProfileParamsKMaybe: KeyMaybe,
FlowParamsKMaybe: KeyMaybe,
{
pub fn workspace_params(&self) -> &WorkspaceParams<WorkspaceParamsK> {
&self.workspace_params
}
}
impl<'ctx, E, O, WorkspaceParamsKMaybe, ProfileParamsK, FlowParamsKMaybe, TS>
MultiProfileSingleFlow<
'ctx,
E,
O,
ParamsKeysImpl<WorkspaceParamsKMaybe, KeyKnown<ProfileParamsK>, FlowParamsKMaybe>,
TS,
>
where
WorkspaceParamsKMaybe: KeyMaybe,
ProfileParamsK:
Clone + Debug + Eq + Hash + DeserializeOwned + Serialize + Send + Sync + 'static,
FlowParamsKMaybe: KeyMaybe,
{
pub fn profile_to_profile_params(&self) -> &BTreeMap<Profile, ProfileParams<ProfileParamsK>> {
&self.profile_to_profile_params
}
}
impl<'ctx, E, O, WorkspaceParamsKMaybe, ProfileParamsKMaybe, FlowParamsK, TS>
MultiProfileSingleFlow<
'ctx,
E,
O,
ParamsKeysImpl<WorkspaceParamsKMaybe, ProfileParamsKMaybe, KeyKnown<FlowParamsK>>,
TS,
>
where
WorkspaceParamsKMaybe: KeyMaybe,
ProfileParamsKMaybe: KeyMaybe,
FlowParamsK: Clone + Debug + Eq + Hash + DeserializeOwned + Serialize + Send + Sync + 'static,
{
pub fn profile_to_flow_params(&self) -> &BTreeMap<Profile, FlowParams<FlowParamsK>> {
&self.profile_to_flow_params
}
}