use std::cell::RefCell;
use std::collections::HashMap;
use super::components_model::SurfaceComponentsModel;
use super::data_model::DataModel;
pub struct PendingAction {
pub action_id: String,
pub response_path: Option<String>,
}
pub struct SurfaceModel {
pub id: String,
pub catalog_id: String,
pub surface_properties: Option<serde_json::Value>,
pub send_data_model: bool,
pub data_model: RefCell<DataModel>,
pub components: RefCell<SurfaceComponentsModel>,
pub pending_actions: RefCell<HashMap<String, PendingAction>>,
}
impl SurfaceModel {
pub fn new(
id: String,
catalog_id: String,
surface_properties: Option<serde_json::Value>,
send_data_model: bool,
) -> Self {
Self {
id,
catalog_id,
surface_properties,
send_data_model,
data_model: RefCell::new(DataModel::new()),
components: RefCell::new(SurfaceComponentsModel::new()),
pending_actions: RefCell::new(HashMap::new()),
}
}
pub fn with_data_model(mut self, data: serde_json::Value) -> Self {
self.data_model = RefCell::new(DataModel::from_value(data));
self
}
pub fn has_root(&self) -> bool {
self.components.borrow().contains("root")
}
}