use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use crate::core::exceptions::{OpError, OperonError};
use crate::core::ops::base::{BaseOp, OpContext, OpMeta};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ParserType {
Json,
Xml,
Yaml,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExtractField {
pub name: String,
#[serde(default)]
pub path: Option<String>,
#[serde(default)]
pub required: bool,
}
pub struct ParserOp {
pub meta: OpMeta,
pub parse_as: ParserType,
pub extract_fields: Vec<ExtractField>,
}
#[async_trait]
impl BaseOp for ParserOp {
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::Parser(format!(
"ParserOp::exec_core not yet implemented (phase 1 scaffold for {})",
self.meta.full_name
))))
}
}