use serde::{Deserialize, Serialize};
use crate::{WritingsTrait, author::Author};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "poem", derive(poem_openapi::Object))]
#[cfg_attr(
feature = "utoipa",
derive(utoipa::ToSchema),
schema(
example = json!(GleaningsParagraph {
number: 2,
roman: "II".to_string(),
paragraph: 1,
ref_id: "958506325".to_string(),
text: "The beginning of all things is the knowledge of God, and the end of all things is strict observance of whatsoever hath been sent down from the empyrean of the Divine Will that pervadeth all that is in the heavens and all that is on the earth.".to_string(),
}),
),
)]
pub struct GleaningsParagraph {
pub ref_id: String,
pub number: u32,
pub roman: String,
pub paragraph: u32,
pub text: String,
}
impl WritingsTrait for GleaningsParagraph {
fn ref_id(&self) -> String {
self.ref_id.clone()
}
fn title(&self) -> String {
"Gleanings from the Writings of Bahá'u'lláh".to_string()
}
fn subtitle(&self) -> Option<String> {
None
}
fn author(&self) -> crate::author::Author {
Author::Bahaullah
}
fn number(&self) -> Option<u32> {
Some(self.number)
}
fn paragraph(&self) -> u32 {
self.paragraph
}
fn text(&self) -> String {
self.text.clone()
}
}
impl GleaningsParagraph {
pub fn roman(&self) -> String {
crate::roman::to(self.number).unwrap_or_else(|| {
panic!("invalid Gleaning number -> Roman Numeral invalid: {self:#?} -- this error should never occur")
})
}
}
#[cfg(feature = "indicium")]
impl indicium::simple::Indexable for GleaningsParagraph {
fn strings(&self) -> Vec<String> {
[
self.ref_id.as_str(),
self.roman.as_str(),
&diacritics::remove_diacritics(&self.text),
]
.iter()
.filter_map(|s| {
if s.is_empty() {
None
} else {
Some(s.to_string())
}
})
.collect()
}
}