use serde::{Deserialize, Serialize};
use crate::error::Result;
use crate::models::conceptual::ConceptualModel;
use crate::models::logical::LogicalModel;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemodelFile {
pub writer: String,
pub conceptual: ConceptualModel,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub logical: Option<LogicalModel>,
}
impl RemodelFile {
pub fn new(conceptual: ConceptualModel) -> Self {
Self {
writer: format!("remodel-core/{}", crate::VERSION),
conceptual,
logical: None,
}
}
pub fn to_json(&self) -> Result<String> {
serde_json::to_string_pretty(self)
.map_err(|e| crate::Error::Internal(format!("serialize: {e}")))
}
pub fn from_json(s: &str) -> Result<Self> {
serde_json::from_str(s).map_err(|e| crate::Error::Internal(format!("parse: {e}")))
}
}