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))]
pub struct BookParagraph {
pub ref_id: String,
pub title: BookTitle,
pub subtitle: Option<String>,
pub number: Option<u32>,
pub paragraph: u32,
pub text: String,
}
impl WritingsTrait for BookParagraph {
fn ref_id(&self) -> String {
self.ref_id.clone()
}
fn title(&self) -> String {
self.title.to_string()
}
fn subtitle(&self) -> Option<String> {
self.subtitle.clone()
}
fn author(&self) -> Author {
self.title.author()
}
fn number(&self) -> Option<u32> {
self.number
}
fn paragraph(&self) -> u32 {
self.paragraph
}
fn text(&self) -> String {
self.text.clone()
}
}
#[cfg(feature = "indicium")]
impl indicium::simple::Indexable for BookParagraph {
fn strings(&self) -> Vec<String> {
[
self.ref_id.as_str(),
&self.title.to_string(),
self.subtitle.as_deref().unwrap_or_default(),
&diacritics::remove_diacritics(&self.text),
]
.iter()
.filter_map(|s| {
if s.is_empty() {
None
} else {
Some(s.to_string())
}
})
.collect()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, strum::Display)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "poem", derive(poem_openapi::Enum))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub enum BookTitle {
#[strum(serialize = "Selections from the Writings of the Báb")]
SelectionsFromTheWritingsOfTheBab,
#[strum(serialize = "Call of the Divine Beloved")]
CallOfTheDivineBeloved,
#[strum(serialize = "Days of Remembrance")]
DaysOfRemembrance,
#[strum(serialize = "Epistle to the Son of the Wolf")]
EpistleToTheSonOfTheWolf,
#[strum(serialize = "Kitáb-i-Aqdas")]
KitabiAqdas,
#[strum(serialize = "Kitáb-i-Íqán")]
KitabiIqan,
#[strum(serialize = "Summons of the Lord of Hosts")]
SummonsOfTheLordOfHosts,
#[strum(serialize = "The Tabernacle of Unity")]
TabernacleOfUnity,
#[strum(serialize = "Tablets of Bahá’u’lláh")]
TabletsOfBahaullah,
#[strum(serialize = "Light of the World: Selected Tablets of ‘Abdu’l-Bahá")]
LightOfTheWorld,
#[strum(serialize = "Memorials of the Faithful")]
MemorialsOfTheFaithful,
#[strum(serialize = "Paris Talks")]
ParisTalks,
#[strum(serialize = "The Promulgation of Universal Peace")]
PromulgationOfUniversalPeace,
#[strum(serialize = "The Secret of Divine Civilization")]
SecretOfDivineCivilization,
#[strum(serialize = "Selections from the Writings of ‘Abdu’l-Bahá")]
SelectionsFromTheWritingsOfAbdulBaha,
#[strum(serialize = "Some Answered Questions")]
SomeAnsweredQuestions,
#[strum(serialize = "Tablet to Dr. Auguste Forel")]
TabletToDrAugusteForel,
#[strum(serialize = "Tablets of the Divine Plan")]
TabletsOfTheDivinePlan,
#[strum(serialize = "Tablets to The Hague")]
TabletsToTheHague,
#[strum(serialize = "A Traveler’s Narrative")]
ATravelersNarrative,
#[strum(serialize = "Twelve Table Talks given by ‘Abdu’l‑Bahá in ‘Akká")]
TwelveTableTalks,
#[strum(serialize = "Will and Testament of ‘Abdu’l‑Bahá")]
WillAndTestamentOfAbdulBaha,
}
impl BookTitle {
pub fn title(&self) -> String {
self.to_string()
}
pub fn author(&self) -> Author {
match self {
BookTitle::SelectionsFromTheWritingsOfTheBab => Author::TheBab,
BookTitle::CallOfTheDivineBeloved => Author::Bahaullah,
BookTitle::DaysOfRemembrance => Author::Bahaullah,
BookTitle::EpistleToTheSonOfTheWolf => Author::Bahaullah,
BookTitle::KitabiAqdas => Author::Bahaullah,
BookTitle::KitabiIqan => Author::Bahaullah,
BookTitle::SummonsOfTheLordOfHosts => Author::Bahaullah,
BookTitle::TabernacleOfUnity => Author::Bahaullah,
BookTitle::TabletsOfBahaullah => Author::Bahaullah,
BookTitle::LightOfTheWorld => Author::AbdulBaha,
BookTitle::MemorialsOfTheFaithful => Author::AbdulBaha,
BookTitle::ParisTalks => Author::AbdulBaha,
BookTitle::PromulgationOfUniversalPeace => Author::AbdulBaha,
BookTitle::SecretOfDivineCivilization => Author::AbdulBaha,
BookTitle::SelectionsFromTheWritingsOfAbdulBaha => Author::AbdulBaha,
BookTitle::SomeAnsweredQuestions => Author::AbdulBaha,
BookTitle::TabletToDrAugusteForel => Author::AbdulBaha,
BookTitle::TabletsOfTheDivinePlan => Author::AbdulBaha,
BookTitle::TabletsToTheHague => Author::AbdulBaha,
BookTitle::ATravelersNarrative => Author::AbdulBaha,
BookTitle::TwelveTableTalks => Author::AbdulBaha,
BookTitle::WillAndTestamentOfAbdulBaha => Author::AbdulBaha,
}
}
}