use std::{collections::BTreeMap, fmt::Debug};
use interruptible::InterruptibilityState;
use own::{OwnedOrMutRef, OwnedOrRef};
use peace_profile_model::Profile;
use peace_resource_rt::paths::{
PeaceAppDir, PeaceDir, ProfileDir, ProfileHistoryDir, WorkspaceDir,
};
use peace_rt_model::{
params::{ProfileParams, WorkspaceParams},
Workspace,
};
use type_reg::untagged::{BoxDt, TypeReg};
use crate::{CmdCtxMpnfParams, CmdCtxMpnfParamsBuilder, CmdCtxTypes};
#[derive(Debug)]
pub struct CmdCtxMpnf<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
pub output: OwnedOrMutRef<'ctx, CmdCtxTypesT::Output>,
pub fields: CmdCtxMpnfFields<'ctx, CmdCtxTypesT>,
}
#[derive(Debug)]
pub struct CmdCtxMpnfFields<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
pub interruptibility_state: InterruptibilityState<'static, 'static>,
pub workspace: OwnedOrRef<'ctx, Workspace>,
pub profiles: Vec<Profile>,
pub profile_dirs: BTreeMap<Profile, ProfileDir>,
pub profile_history_dirs: BTreeMap<Profile, ProfileHistoryDir>,
pub workspace_params_type_reg: TypeReg<CmdCtxTypesT::WorkspaceParamsKey, BoxDt>,
pub workspace_params: WorkspaceParams<CmdCtxTypesT::WorkspaceParamsKey>,
pub profile_params_type_reg: TypeReg<CmdCtxTypesT::ProfileParamsKey, BoxDt>,
pub profile_to_profile_params: BTreeMap<Profile, ProfileParams<CmdCtxTypesT::ProfileParamsKey>>,
}
impl<'ctx, CmdCtxTypesT> CmdCtxMpnf<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
pub fn builder<'ctx_local>() -> CmdCtxMpnfParamsBuilder<'ctx_local, CmdCtxTypesT> {
CmdCtxMpnfParams::<'ctx_local, CmdCtxTypesT>::builder()
}
pub fn output(&self) -> &CmdCtxTypesT::Output {
&self.output
}
pub fn output_mut(&mut self) -> &mut CmdCtxTypesT::Output {
&mut self.output
}
pub fn fields(&self) -> &CmdCtxMpnfFields<'_, CmdCtxTypesT> {
&self.fields
}
pub fn fields_mut(&mut self) -> &mut CmdCtxMpnfFields<'ctx, CmdCtxTypesT> {
&mut self.fields
}
}
impl<CmdCtxTypesT> CmdCtxMpnfFields<'_, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
pub fn interruptibility_state(&mut self) -> InterruptibilityState<'_, '_> {
self.interruptibility_state.reborrow()
}
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 workspace_params_type_reg(&self) -> &TypeReg<CmdCtxTypesT::WorkspaceParamsKey, BoxDt> {
&self.workspace_params_type_reg
}
pub fn workspace_params_type_reg_mut(
&mut self,
) -> &mut TypeReg<CmdCtxTypesT::WorkspaceParamsKey, BoxDt> {
&mut self.workspace_params_type_reg
}
pub fn workspace_params(&self) -> &WorkspaceParams<CmdCtxTypesT::WorkspaceParamsKey> {
&self.workspace_params
}
pub fn workspace_params_mut(
&mut self,
) -> &mut WorkspaceParams<CmdCtxTypesT::WorkspaceParamsKey> {
&mut self.workspace_params
}
pub fn profile_params_type_reg(&self) -> &TypeReg<CmdCtxTypesT::ProfileParamsKey, BoxDt> {
&self.profile_params_type_reg
}
pub fn profile_params_type_reg_mut(
&mut self,
) -> &mut TypeReg<CmdCtxTypesT::ProfileParamsKey, BoxDt> {
&mut self.profile_params_type_reg
}
pub fn profile_to_profile_params(
&self,
) -> &BTreeMap<Profile, ProfileParams<CmdCtxTypesT::ProfileParamsKey>> {
&self.profile_to_profile_params
}
pub fn profile_to_profile_params_mut(
&mut self,
) -> &mut BTreeMap<Profile, ProfileParams<CmdCtxTypesT::ProfileParamsKey>> {
&mut self.profile_to_profile_params
}
}