use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Reference {
pub identifier: String,
pub group: Option<String>,
#[serde(rename = "type")]
pub reference_type: ReferenceType,
pub metadata: Option<serde_json::Value>,
pub text: ReferenceText,
pub source: Option<serde_json::Value>,
pub parent_reference: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ReferenceType {
Web,
Book,
Text,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct ReferenceText {
pub html: Option<String>,
pub plain_text: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Citation {
pub identifier: String,
pub text: Option<String>,
pub reference_id: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_reference_creation() {
let reference = Reference {
identifier: "cite_note-36".to_string(),
group: None,
reference_type: ReferenceType::Web,
metadata: Some(serde_json::json!({
"title": "Example Article",
"url": "https://example.com",
})),
text: ReferenceText {
html: Some("<i>Example Article</i>".to_string()),
plain_text: Some("Example Article".to_string()),
},
source: None,
parent_reference: None,
};
assert_eq!(reference.identifier, "cite_note-36");
assert!(matches!(reference.reference_type, ReferenceType::Web));
}
#[test]
fn test_citation_creation() {
let citation = Citation {
identifier: "cite_note-78".to_string(),
text: Some("[78]".to_string()),
reference_id: Some("cite_note-78".to_string()),
};
assert_eq!(citation.identifier, "cite_note-78");
assert_eq!(citation.text, Some("[78]".to_string()));
}
#[test]
fn test_reference_types() {
let web = ReferenceType::Web;
let book = ReferenceType::Book;
let text = ReferenceType::Text;
assert!(matches!(web, ReferenceType::Web));
assert!(matches!(book, ReferenceType::Book));
assert!(matches!(text, ReferenceType::Text));
}
}