use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ConfigNode {
pub node_name: String,
#[serde(skip)]
pub uuid: Uuid,
pub configurations: Vec<String>,
pub connections: ConfigNodeNetwork,
}
impl ConfigNode {
pub fn new(node_name: String) -> Self {
ConfigNode {
node_name,
uuid: Uuid::new_v4(),
configurations: Vec::new(),
connections: ConfigNodeNetwork {
node_network: HashMap::new(),
},
}
}
pub fn add_configuration(&mut self, config_str:String) {
let configs = &mut self.configurations;
configs.push(config_str);
}
pub fn add_connection(&mut self, node_name: String, key: Option<String>) -> Option<&mut ConfigNode> {
let mut hash_key = "Any".to_string();
if key.is_some() {
hash_key = key.unwrap();
}
let config_node = self.connections.add_node(node_name, Some(hash_key));
config_node
}
}