use serde::{Deserialize, Serialize};
use hwpforge_core::document::Document;
use hwpforge_core::section::Section;
use hwpforge_core::Draft;
use crate::HwpxStyleStore;
pub const SECTION_PRESERVATION_VERSION: u32 = 1;
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ExportedDocument {
pub document: Document<Draft>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schemars", schemars(skip))]
pub styles: Option<HwpxStyleStore>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct SectionPreservation {
#[serde(default)]
pub preservation_version: u32,
pub section_path: String,
pub section_sha256: String,
pub text_slots: Vec<PreservedTextSlot>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct PreservedTextSlot {
pub path: String,
pub original_text: String,
#[serde(default)]
pub has_inline_markup: bool,
pub locator: TextLocator,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum TextLocator {
TextElement {
element_start: usize,
element_end: usize,
content_start: Option<usize>,
content_end: Option<usize>,
},
EmptyRun {
run_start: usize,
run_end: usize,
},
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ExportedSection {
pub section_index: usize,
pub section: Section,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "schemars", schemars(skip))]
pub styles: Option<HwpxStyleStore>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preservation: Option<SectionPreservation>,
}