use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
use super::common::ID;
use crate::utils::serde::parse_stringint;
pub type Annotations = Vec<Annotation>;
#[derive(Deserialize, Serialize, Debug)]
pub struct Annotation {
pub id: ID,
pub annotator_schema_version: String,
pub created_at: DateTime<Utc>,
pub quote: Option<String>,
pub ranges: Vec<Range>,
pub text: String,
pub updated_at: DateTime<Utc>,
pub user: Option<String>,
}
impl From<Annotation> for ID {
fn from(ann: Annotation) -> Self {
ann.id
}
}
impl From<&Annotation> for ID {
fn from(ann: &Annotation) -> Self {
ann.id
}
}
#[derive(Deserialize, Debug)]
pub(crate) struct AnnotationRows {
pub rows: Annotations,
}
#[derive(Serialize, Debug)]
pub struct NewAnnotation {
pub quote: String,
pub ranges: Vec<Range>,
pub text: String,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Range {
pub start: Option<String>,
pub end: Option<String>,
#[serde(deserialize_with = "parse_stringint")]
pub start_offset: u32,
#[serde(deserialize_with = "parse_stringint")]
pub end_offset: u32,
}