use crate::engine::outcomes::RelationDeclared;
use crate::entity::Entity;
use crate::ops::{ModifiedMetadata, ModifiedSections, WarningHint};
use super::{PreparedUpdate, UpdateEntityOutcome};
pub(super) fn noop_outcome(
next: &Entity,
file_path: String,
relations_declared: Vec<RelationDeclared>,
anchors_changed: Option<bool>,
) -> UpdateEntityOutcome {
let modified_date = next
.metadata
.get("last_modified")
.and_then(|v| v.as_str().map(str::to_string))
.unwrap_or_default();
UpdateEntityOutcome {
id: next.id.clone(),
title: next.title.clone(),
file_path,
content_hash: next.content_hash.clone(),
write_id: String::new(),
modified_date,
modified_sections: ModifiedSections::default(),
modified_metadata: ModifiedMetadata::default(),
prospective_hash: None,
orphan_stubs_removed: Vec::new(),
warnings: vec![WarningHint::UpdateNoop {
id: next.id.clone(),
}],
relations_declared,
anchors_changed,
}
}
pub(super) fn dry_run_outcome(
prepared: PreparedUpdate,
title: String,
current_hash: String,
modified_date: String,
) -> UpdateEntityOutcome {
let prospective = crate::entity::parser::compute_hash(&prepared.markdown);
UpdateEntityOutcome {
id: prepared.id,
title,
file_path: prepared.file_path,
content_hash: current_hash,
write_id: String::new(),
modified_date,
modified_sections: prepared.modified_sections,
modified_metadata: prepared.modified_metadata,
prospective_hash: Some(prospective),
orphan_stubs_removed: Vec::new(),
warnings: prepared.warnings,
relations_declared: prepared.relations_declared,
anchors_changed: prepared.anchors_changed,
}
}