use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AnnotationType {
Primary,
Secondary,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Annotation {
pub message: Option<String>,
pub r#type: AnnotationType,
pub origin: String,
pub from: usize,
pub to: usize,
}
impl Annotation {
pub fn new<O: Into<String>>(r#type: AnnotationType, origin: O, from: usize, to: usize) -> Self {
Self {
r#type,
message: None,
origin: origin.into(),
from,
to,
}
}
pub fn primary<O: Into<String>>(origin: O, from: usize, to: usize) -> Self {
Self::new(AnnotationType::Primary, origin, from, to)
}
pub fn secondary<O: Into<String>>(origin: O, from: usize, to: usize) -> Self {
Self::new(AnnotationType::Secondary, origin, from, to)
}
#[must_use]
pub fn with_message<S: Into<String>>(mut self, message: S) -> Self {
self.message = Some(message.into());
self
}
}