use std::collections::HashMap;
pub trait CimElement: Send + Sync {
fn mrid(&self) -> &str;
fn type_name(&self) -> &'static str;
fn as_any(&self) -> &dyn std::any::Any;
fn to_json_value(&self) -> serde_json::Value;
fn to_block(&self) -> RdfBlock;
}
#[derive(Debug, Clone)]
pub enum FieldValue {
Text(String),
TextList(Vec<String>),
Resource(String),
ResourceList(Vec<String>),
}
#[derive(Debug, Clone)]
pub struct RdfBlock {
pub type_name: String,
pub mrid: String,
pub fields: HashMap<String, FieldValue>,
pub duplicate_fields: std::collections::HashSet<String>,
}
impl Default for RdfBlock {
fn default() -> Self {
Self {
type_name: String::new(),
mrid: String::new(),
fields: HashMap::new(),
duplicate_fields: std::collections::HashSet::new(),
}
}
}
impl RdfBlock {
pub fn merge_from(&mut self, other: &RdfBlock) {
for (k, v) in &other.fields {
match v {
FieldValue::ResourceList(new_list) => {
match self.fields.get_mut(k) {
Some(FieldValue::ResourceList(existing)) => {
existing.extend(new_list.iter().cloned())
}
_ => {
self.fields.insert(k.clone(), v.clone());
}
}
}
_ => {
self.fields.insert(k.clone(), v.clone());
}
}
}
}
}
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[serde(transparent)]
pub struct MridRef {
pub mrid: String,
}
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[serde(transparent)]
pub struct UriRef {
pub uri: String,
}