use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
#[cfg(feature = "comfy-renderer")]
use crate::services::comfy::ValidatedWorkflowTemplate;
#[cfg(feature = "comfy-renderer")]
#[derive(Clone)]
pub struct ComfyContext {
pub workflow: Arc<ValidatedWorkflowTemplate>,
pub runtime_handle: tokio::runtime::Handle,
}
#[cfg(feature = "comfy-renderer")]
impl ComfyContext {
pub fn new(
workflow: ValidatedWorkflowTemplate,
runtime_handle: tokio::runtime::Handle,
) -> Self {
Self { workflow: Arc::new(workflow), runtime_handle }
}
}
#[derive(Clone)]
pub struct PythonContext {
pub interpreter: Option<Arc<PathBuf>>,
pub script_root: Option<Arc<PathBuf>>,
pub environment: Option<Arc<HashMap<String, String>>>,
}
impl PythonContext {
pub fn new(
interpreter: Option<PathBuf>,
script_root: Option<PathBuf>,
environment: Option<HashMap<String, String>>,
) -> Self {
Self {
interpreter: interpreter.map(Arc::new),
script_root: script_root.map(Arc::new),
environment: environment.map(Arc::new),
}
}
}
#[derive(Clone, Default)]
pub struct BuildContext {
#[cfg(feature = "comfy-renderer")]
comfy: Option<ComfyContext>,
python: Option<PythonContext>,
}
impl BuildContext {
pub fn builder() -> BuildContextBuilder {
BuildContextBuilder::default()
}
#[cfg(feature = "comfy-renderer")]
pub fn comfy(&self) -> Option<&ComfyContext> {
self.comfy.as_ref()
}
pub fn python(&self) -> Option<&PythonContext> {
self.python.as_ref()
}
}
#[derive(Default)]
pub struct BuildContextBuilder {
#[cfg(feature = "comfy-renderer")]
comfy: Option<ComfyContext>,
python: Option<PythonContext>,
}
impl BuildContextBuilder {
#[cfg(feature = "comfy-renderer")]
pub fn with_comfy(mut self, ctx: ComfyContext) -> Self {
self.comfy = Some(ctx);
self
}
pub fn with_python(mut self, ctx: PythonContext) -> Self {
self.python = Some(ctx);
self
}
pub fn build(self) -> BuildContext {
BuildContext {
#[cfg(feature = "comfy-renderer")]
comfy: self.comfy,
python: self.python,
}
}
}