use std::{collections::HashMap, error::Error, fmt};
use crate::{event::Event, interpreter::EcmaScriptValue, StateChartId};
use uuid::Uuid;
#[derive(Clone, Debug, PartialEq)]
pub struct SystemVariables {
_event: Option<Event>,
_sessionid: Uuid,
_name: StateChartId,
_ioprocessors: Vec<String>,
_x: HashMap<String, EcmaScriptValue>,
}
#[derive(Debug, PartialEq)]
pub enum DataModelError {
InvalidValueType(String ),
}
impl SystemVariables {
pub fn _event(&self) -> Option<Event> {
self._event.as_ref().cloned()
}
pub fn _x(&self) -> &HashMap<String, EcmaScriptValue> {
&self._x
}
pub fn get_data_member(&self, id: &str) -> Option<&EcmaScriptValue> {
self._x.get(id)
}
pub fn set_name(&mut self, name: String) {
self._name = name;
}
pub fn set_event(&mut self, event: Event) {
self._event = Some(event);
}
pub fn set_data_member(&mut self, id: &str, value: EcmaScriptValue) -> Option<EcmaScriptValue> {
self._x.insert(id.to_string(), value)
}
}
impl Error for DataModelError {}
impl fmt::Display for DataModelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::InvalidValueType(identifier_name) => {
write!(
f,
"Type of identifier '{}' is and invalid type.",
identifier_name
)
}
}
}
}
impl Default for SystemVariables {
fn default() -> Self {
Self {
_event: None,
_sessionid: Uuid::new_v4(),
_name: String::new(),
_ioprocessors: Vec::new(),
_x: HashMap::default(),
}
}
}