pub mod annotation;
pub mod ids;
pub mod library;
pub mod reference;
pub mod snapshot;

pub use annotation::{
    Annotation, AnnotationSet, AnnotationType, Color, Point, Quad, Rect, TextMarkupType,
};
pub use ids::{AnnotationId, LibraryId, ReferenceId};
pub use library::Library;
pub use reference::{EntryType, PdfAttachment, Person, Reference};
pub use snapshot::Snapshot;

/// TOML round-trip tests for model types used in on-disk storage.
///
/// These live in brittle-core (not brittle-model) because TOML is a
/// brittle-core persistence concern — brittle-model itself is TOML-agnostic.
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn reference_toml_round_trip() {
        let mut r = Reference::new("doe2024", EntryType::Article);
        r.authors.push(Person {
            family: "Doe".into(),
            given: Some("Jane".into()),
            prefix: None,
            suffix: None,
        });
        r.fields.insert("title".into(), "A Great Paper".into());
        r.fields.insert("year".into(), "2024".into());

        let toml_str = toml::to_string(&r).expect("serialize to TOML");
        let r2: Reference = toml::from_str(&toml_str).expect("deserialize from TOML");

        assert_eq!(r.id, r2.id);
        assert_eq!(r.cite_key, r2.cite_key);
        assert_eq!(r.authors, r2.authors);
        assert_eq!(r.fields, r2.fields);
    }

    #[test]
    fn library_toml_round_trip() {
        let mut lib = Library::new("Machine Learning", None);
        lib.members.insert(ReferenceId::new());

        let toml_str = toml::to_string(&lib).expect("serialize to TOML");
        let lib2: Library = toml::from_str(&toml_str).expect("deserialize from TOML");

        assert_eq!(lib.id, lib2.id);
        assert_eq!(lib.name, lib2.name);
        assert_eq!(lib.members, lib2.members);
    }

    #[test]
    fn annotation_toml_round_trip() {
        let ref_id = ReferenceId::new();
        let set = AnnotationSet {
            reference_id: ref_id,
            annotations: vec![Annotation::new(
                ref_id,
                3,
                AnnotationType::TextMarkup {
                    markup_type: TextMarkupType::Highlight,
                    quads: vec![],
                    color: Color::YELLOW,
                    selected_text: Some("key phrase".into()),
                },
            )],
        };

        let toml_str = toml::to_string(&set).expect("serialize to TOML");
        let set2: AnnotationSet = toml::from_str(&toml_str).expect("deserialize from TOML");

        assert_eq!(set.reference_id, set2.reference_id);
        assert_eq!(set.annotations[0].page, set2.annotations[0].page);
    }
}
