use std::sync::Arc;
use async_trait::async_trait;
use serde_json::{Map, Value};
use crate::core::configs::op_config::{OpConfig, OpType};
use crate::core::exceptions::{OpError, OperonError};
use crate::core::ops::base::{BaseOp, OpContext, OpMeta};
pub struct GraphOp {
pub meta: OpMeta,
pub config: Arc<OpConfig>,
}
impl GraphOp {
pub fn new(config: Arc<OpConfig>) -> Result<Self, OperonError> {
if !matches!(config.kind, OpType::Graph) {
return Err(OperonError::Config(format!(
"GraphOp requires type=\"graph\"; got {:?}",
config.kind
)));
}
let meta = OpMeta {
name: config.name.clone(),
full_name: config.full_name.clone(),
kind: config.kind,
enabled: config.enabled,
verbose: config.verbose,
stream: config.stream,
bound: config.bound,
inputs: config
.inputs
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
outputs: config
.outputs
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
cache: config.cache.clone(),
delay: config.delay,
};
Ok(Self { meta, config })
}
}
#[async_trait]
impl BaseOp for GraphOp {
fn meta(&self) -> &OpMeta {
&self.meta
}
async fn exec_core(
&self,
_inputs: Map<String, Value>,
_ctx: &OpContext<'_>,
) -> Result<Option<Value>, OperonError> {
Err(OperonError::Op(OpError::code_msg(
format!(
"nested GraphOp::exec_core not yet implemented (Phase 4 scaffolding for '{}')",
self.meta.full_name
),
self.meta.full_name.clone(),
)))
}
}