writings/
additional_tablet.rs1use serde::{Deserialize, Serialize};
2
3use crate::{WritingsTrait, author::Author};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8#[cfg_attr(feature = "poem", derive(poem_openapi::Object))]
9#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
10pub struct TabletParagraph {
11 pub source: TabletSource,
12 pub ref_id: String,
13 pub number: Option<u32>,
14 pub paragraph: u32,
15 pub text: String,
16}
17
18impl WritingsTrait for TabletParagraph {
19 fn ref_id(&self) -> String {
20 self.ref_id.clone()
21 }
22
23 fn title(&self) -> String {
24 self.source.title()
25 }
26
27 fn subtitle(&self) -> Option<String> {
28 None
29 }
30
31 fn author(&self) -> Author {
32 self.source.author()
33 }
34
35 fn number(&self) -> Option<u32> {
36 self.number
37 }
38
39 fn paragraph(&self) -> u32 {
40 self.paragraph
41 }
42
43 fn text(&self) -> String {
44 self.text.clone()
45 }
46}
47
48#[cfg(feature = "indicium")]
49impl indicium::simple::Indexable for TabletParagraph {
50 fn strings(&self) -> Vec<String> {
51 [
52 self.ref_id.as_str(),
53 &self.source.to_string(),
54 &diacritics::remove_diacritics(&self.text),
55 ]
56 .iter()
57 .filter_map(|s| {
58 if s.is_empty() {
59 None
60 } else {
61 Some(s.to_string())
62 }
63 })
64 .collect()
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, strum::Display)]
70#[serde(rename_all = "camelCase")]
71#[cfg_attr(feature = "poem", derive(poem_openapi::Enum))]
72#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
73pub enum TabletSource {
74 #[strum(serialize = "Additional Tablets and Extracts from Tablets Revealed by Bahá'u'lláh")]
76 AdditionalTabletsAndExtractsBahaullah,
81 #[strum(serialize = "Additional Tablets, Extracts, and Talks by 'Abdu'l‑Bahá")]
83 AdditionalTabletsExtractsAndTalksAbdulBaha,
88}
89
90impl TabletSource {
91 pub fn title(&self) -> String {
92 self.to_string()
93 }
94
95 pub fn author(&self) -> Author {
96 match self {
97 TabletSource::AdditionalTabletsAndExtractsBahaullah => Author::Bahaullah,
98 TabletSource::AdditionalTabletsExtractsAndTalksAbdulBaha => Author::AbdulBaha,
99 }
100 }
101}