use serde::{Deserialize, Serialize};
use crate::presentation::{LangMap, Resource};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AnnotationPage {
pub id: String,
#[serde(default = "annotation_page_type")]
pub r#type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<LangMap>,
pub items: Vec<Annotation>,
}
fn annotation_page_type() -> String {
"AnnotationPage".to_string()
}
impl Default for AnnotationPage {
fn default() -> Self {
Self {
id: "".to_string(),
r#type: annotation_page_type(),
label: None,
items: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Annotation {
pub id: String,
#[serde(default = "annotation_type")]
pub r#type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<LangMap>,
pub motivation: String,
pub target: String,
pub body: Resource,
}
fn annotation_type() -> String {
"Annotation".to_string()
}
impl Default for Annotation {
fn default() -> Self {
Self {
id: "".to_string(),
r#type: annotation_type(),
label: None,
motivation: "".to_string(),
target: "".to_string(),
body: Resource::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_annotation_page_default() {
let annotation_page = AnnotationPage::default();
assert_eq!(annotation_page.id, "");
assert_eq!(annotation_page.r#type, "AnnotationPage");
}
#[test]
fn test_annotation_default() {
let annotation = Annotation::default();
assert_eq!(annotation.id, "");
assert_eq!(annotation.r#type, "Annotation");
}
}