//! Document: filename + mime + pointer to the primary attachment blob.

use serde::{Deserialize, Serialize};

use crate::ids::AttachmentId;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentCore {
    pub filename: String,
    pub mime_type: String,
    pub primary_attachment: AttachmentId,
}

impl Default for DocumentCore {
    fn default() -> Self {
        Self {
            filename: String::new(),
            mime_type: "application/octet-stream".into(),
            primary_attachment: AttachmentId(String::new()),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn document_round_trip() {
        let doc = DocumentCore {
            filename: "passport.pdf".into(),
            mime_type: "application/pdf".into(),
            primary_attachment: AttachmentId("0123456789abcdef".into()),
        };
        let json = serde_json::to_string(&doc).unwrap();
        let parsed: DocumentCore = serde_json::from_str(&json).unwrap();
        assert_eq!(parsed.filename, "passport.pdf");
        assert_eq!(parsed.primary_attachment.as_str(), "0123456789abcdef");
    }
}
