1use serde::{Deserialize, Serialize};
4
5use crate::errors::ModelError;
6
7pub const CURRENT_BIBLE_SCHEMA_VERSION: u32 = 1;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12#[serde(rename_all = "snake_case")]
13pub enum BibleLoadPhase {
14 Reading,
16 Processing,
18 Complete,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct BibleLoadProgress {
26 pub phase: BibleLoadPhase,
28 pub fraction: f32,
30 pub phase_fraction: f32,
32}
33
34impl BibleLoadProgress {
35 pub fn new(
37 phase: BibleLoadPhase,
38 fraction: f32,
39 phase_fraction: f32,
40 ) -> Result<Self, ModelError> {
41 if !fraction.is_finite() || !(0.0..=1.0).contains(&fraction) {
42 return Err(ModelError::new(
43 "fraction",
44 "must be finite and between 0 and 1",
45 ));
46 }
47 if !phase_fraction.is_finite() || !(0.0..=1.0).contains(&phase_fraction) {
48 return Err(ModelError::new(
49 "phase_fraction",
50 "must be finite and between 0 and 1",
51 ));
52 }
53 Ok(Self {
54 phase,
55 fraction,
56 phase_fraction,
57 })
58 }
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct BibleDataValidationOptions {
65 pub require_books: bool,
67 pub require_chapters: bool,
69 pub require_verses: bool,
71 pub require_verse_text: bool,
73}
74
75impl BibleDataValidationOptions {
76 pub const PERMISSIVE: Self = Self {
78 require_books: false,
79 require_chapters: false,
80 require_verses: false,
81 require_verse_text: false,
82 };
83}
84
85impl Default for BibleDataValidationOptions {
86 fn default() -> Self {
87 Self {
88 require_books: true,
89 require_chapters: true,
90 require_verses: true,
91 require_verse_text: true,
92 }
93 }
94}
95
96#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
98#[serde(rename_all = "camelCase")]
99pub struct BibleLoadOptions {
100 pub validation: BibleDataValidationOptions,
102 pub search_index_mode: crate::search::SearchIndexMode,
104}