use serde::{Deserialize, Serialize};
use crate::errors::ModelError;
pub const CURRENT_BIBLE_SCHEMA_VERSION: u32 = 1;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BibleLoadPhase {
Reading,
Processing,
Complete,
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BibleLoadProgress {
pub phase: BibleLoadPhase,
pub fraction: f32,
pub phase_fraction: f32,
}
impl BibleLoadProgress {
pub fn new(
phase: BibleLoadPhase,
fraction: f32,
phase_fraction: f32,
) -> Result<Self, ModelError> {
if !fraction.is_finite() || !(0.0..=1.0).contains(&fraction) {
return Err(ModelError::new(
"fraction",
"must be finite and between 0 and 1",
));
}
if !phase_fraction.is_finite() || !(0.0..=1.0).contains(&phase_fraction) {
return Err(ModelError::new(
"phase_fraction",
"must be finite and between 0 and 1",
));
}
Ok(Self {
phase,
fraction,
phase_fraction,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BibleDataValidationOptions {
pub require_books: bool,
pub require_chapters: bool,
pub require_verses: bool,
pub require_verse_text: bool,
}
impl BibleDataValidationOptions {
pub const PERMISSIVE: Self = Self {
require_books: false,
require_chapters: false,
require_verses: false,
require_verse_text: false,
};
}
impl Default for BibleDataValidationOptions {
fn default() -> Self {
Self {
require_books: true,
require_chapters: true,
require_verses: true,
require_verse_text: true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BibleLoadOptions {
pub validation: BibleDataValidationOptions,
pub search_index_mode: crate::search::SearchIndexMode,
}