#[cfg(feature = "comfy-renderer")]
use crate::backend::BuildContext;
#[cfg(feature = "comfy-renderer")]
use crate::config::model::ComfyConfig;
#[cfg(feature = "comfy-renderer")]
use crate::renderer::{ComfyUIRenderer, ImageRenderer};
#[cfg(feature = "comfy-renderer")]
use crate::services::comfy::{ComfyClient, ComfyConfig as SvcComfyConfig};
use super::FactoryError;
#[cfg(feature = "comfy-renderer")]
pub fn build(
cfg: &ComfyConfig,
ctx: &BuildContext,
) -> Result<Box<dyn ImageRenderer>, FactoryError> {
let comfy_ctx = ctx.comfy().ok_or_else(|| FactoryError::BuildFailed {
backend: "comfy".to_string(),
source: anyhow::anyhow!("ComfyUI context not provided"),
})?;
let svc_config = SvcComfyConfig::new(
cfg.base_url.clone(),
cfg.timeout_secs,
cfg.poll_timeout_secs,
cfg.poll_interval_ms,
);
let client = ComfyClient::new(svc_config)
.map_err(|e| FactoryError::BuildFailed { backend: "comfy".to_string(), source: e })?;
let renderer = ComfyUIRenderer::new(
client,
(*comfy_ctx.workflow).clone(),
comfy_ctx.runtime_handle.clone(),
);
Ok(Box::new(renderer))
}
#[cfg(not(feature = "comfy-renderer"))]
pub fn build(
_cfg: &crate::config::model::ComfyConfig,
_ctx: &crate::backend::BuildContext,
) -> Result<Box<dyn crate::renderer::ImageRenderer>, FactoryError> {
Err(FactoryError::BuildFailed {
backend: "comfy".to_string(),
source: anyhow::anyhow!(
"ComfyUI backend not available (feature 'comfy-renderer' not enabled)"
),
})
}