//! Conversion traits for serializing/deserializing the editor's [`Document`]
//! to and from external formats (Markdown, PDF, HTML, ...).
//!
//! Implementors live in dedicated crates (`devup-editor-markdown`, `devup-editor-pdf`, ...)
//! so the core engine has zero format-specific dependencies.

use crate::model::document::Document;

/// Convert a [`Document`] to an external format.
///
/// Implement this for one-shot exporters (PDF, image, etc.) and lossless
/// round-trippable formats (Markdown, HTML).
pub trait DocumentExport {
    /// The serialized representation (e.g. `String` for text, `Vec<u8>` for binary).
    type Output;
    /// Conversion error type.
    type Error;

    /// Serialize `doc` to the target format.
    fn export(doc: &Document) -> Result<Self::Output, Self::Error>;
}

/// Parse an external format into a [`Document`].
///
/// Block IDs are generated via the supplied [`IdGenerator`] so importers stay
/// deterministic in tests.
pub trait DocumentImport {
    /// The serialized representation to parse.
    type Input;
    /// Conversion error type.
    type Error;

    /// Parse `input` into a `Document`. The provided `id_gen` is used for any
    /// new block IDs created during parsing.
    fn import(
        input: Self::Input,
        id_gen: &mut dyn crate::id::IdGenerator,
    ) -> Result<Document, Self::Error>;
}
