#![allow(
unused_imports,
dead_code,
non_camel_case_types,
unused_variables,
unexpected_cfgs,
clippy::all
)]
use super::context::{LoadContext, SaveContext};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PowerPointInvariants {
pub all_relationship_ids_resolve: bool,
pub all_content_types_declared: bool,
pub no_duplicate_relationship_ids: bool,
pub no_orphan_required_parts: bool,
pub all_slides_reachable: bool,
pub all_media_parts_reachable: bool,
pub all_hyperlinks_have_relationships: bool,
}
impl PowerPointInvariants {
pub fn new() -> Self {
Self::default()
}
pub fn from_json(json: &str, ctx: &LoadContext) -> Result<Self, serde_json::Error> {
let value: serde_json::Value = serde_json::from_str(json)?;
Self::validate_input_at(&value, "")
.map_err(|message| <serde_json::Error as serde::de::Error>::custom(message))?;
Ok(Self::load_from_value(&value, ctx))
}
pub fn from_yaml(yaml: &str, ctx: &LoadContext) -> Result<Self, serde_yaml::Error> {
let value: serde_json::Value = serde_yaml::from_str(yaml)?;
Self::validate_input_at(&value, "")
.map_err(|message| <serde_yaml::Error as serde::de::Error>::custom(message))?;
Ok(Self::load_from_value(&value, ctx))
}
pub fn try_load_from_value(
value: &serde_json::Value,
ctx: &LoadContext,
) -> Result<Self, serde_json::Error> {
Self::validate_input_at(value, "")
.map_err(|message| <serde_json::Error as serde::de::Error>::custom(message))?;
Ok(Self::load_from_value(value, ctx))
}
pub fn load_from_value(value: &serde_json::Value, ctx: &LoadContext) -> Self {
let value = ctx.process_input(value.clone());
if let Err(message) = Self::validate_input_at(&value, "") {
panic!("{}", message);
}
Self {
all_relationship_ids_resolve: value
.get("allRelationshipIdsResolve")
.and_then(|v| v.as_bool())
.unwrap_or(false),
all_content_types_declared: value
.get("allContentTypesDeclared")
.and_then(|v| v.as_bool())
.unwrap_or(false),
no_duplicate_relationship_ids: value
.get("noDuplicateRelationshipIds")
.and_then(|v| v.as_bool())
.unwrap_or(false),
no_orphan_required_parts: value
.get("noOrphanRequiredParts")
.and_then(|v| v.as_bool())
.unwrap_or(false),
all_slides_reachable: value
.get("allSlidesReachable")
.and_then(|v| v.as_bool())
.unwrap_or(false),
all_media_parts_reachable: value
.get("allMediaPartsReachable")
.and_then(|v| v.as_bool())
.unwrap_or(false),
all_hyperlinks_have_relationships: value
.get("allHyperlinksHaveRelationships")
.and_then(|v| v.as_bool())
.unwrap_or(false),
}
}
pub(crate) fn validate_input_at(value: &serde_json::Value, path: &str) -> Result<(), String> {
Ok(())
}
pub fn to_value(&self, ctx: &SaveContext) -> serde_json::Value {
let mut result = serde_json::Map::new();
result.insert(
"allRelationshipIdsResolve".to_string(),
serde_json::Value::Bool(self.all_relationship_ids_resolve),
);
result.insert(
"allContentTypesDeclared".to_string(),
serde_json::Value::Bool(self.all_content_types_declared),
);
result.insert(
"noDuplicateRelationshipIds".to_string(),
serde_json::Value::Bool(self.no_duplicate_relationship_ids),
);
result.insert(
"noOrphanRequiredParts".to_string(),
serde_json::Value::Bool(self.no_orphan_required_parts),
);
result.insert(
"allSlidesReachable".to_string(),
serde_json::Value::Bool(self.all_slides_reachable),
);
result.insert(
"allMediaPartsReachable".to_string(),
serde_json::Value::Bool(self.all_media_parts_reachable),
);
result.insert(
"allHyperlinksHaveRelationships".to_string(),
serde_json::Value::Bool(self.all_hyperlinks_have_relationships),
);
ctx.process_dict(serde_json::Value::Object(result))
}
pub fn to_json(&self, ctx: &SaveContext) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(&self.to_value(ctx))
}
pub fn to_yaml(&self, ctx: &SaveContext) -> Result<String, serde_yaml::Error> {
serde_yaml::to_string(&self.to_value(ctx))
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for PowerPointInvariants {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serde::Serialize::serialize(&self.to_value(&SaveContext::default()), serializer)
}
}
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for PowerPointInvariants {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = <serde_json::Value as serde::Deserialize>::deserialize(deserializer)?;
Self::validate_input_at(&value, "").map_err(serde::de::Error::custom)?;
Ok(Self::load_from_value(&value, &LoadContext::default()))
}
}