use crate::{DetItem, Family, Intent, Moment, Query, SchoolItem, Subject};
use serde::Serialize;
use serde_json::Value;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Bearing {
pub leaf: &'static str,
pub element: String,
pub at: String,
pub direction: &'static str,
pub note: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Principal {
pub label: &'static str,
pub value: String,
}
pub trait CastingEngine: Send + Sync {
fn id(&self) -> &'static str;
fn name(&self) -> &'static str;
fn family(&self) -> Family;
fn cast(&self, m: &Moment, q: &Query) -> Value;
fn profile(&self) -> &'static [DetItem] {
&[]
}
fn bearings(&self, _m: &Moment, _q: &Query) -> Vec<Bearing> {
Vec::new()
}
fn schools(&self) -> &'static [SchoolItem] {
&[]
}
fn answers(&self) -> &'static [Intent] {
&[Intent::Natal]
}
fn reading_notes(&self) -> Option<&'static str> {
None
}
fn subject_notes(&self, _subject: Subject) -> Option<&'static str> {
None
}
fn principal(&self, _m: &Moment, _q: &Query) -> Option<Principal> {
None
}
}
#[derive(Debug, Clone, Serialize)]
pub struct LeafOutput {
pub id: &'static str,
pub name: &'static str,
pub family: Family,
pub family_label: &'static str,
pub profile: &'static [DetItem],
pub schools: &'static [SchoolItem],
pub effective_school: String,
pub chart: Value,
}
#[must_use]
pub fn effective_school_id(e: &dyn CastingEngine, q: &Query) -> String {
if let Some(sel) = q.schools.get(e.id()) {
return sel.clone();
}
e.schools()
.iter()
.find(|s| s.default)
.map_or_else(String::new, |s| s.id.to_string())
}
#[derive(Debug, Clone, Default, Serialize, serde::Deserialize)]
pub struct WordQuery {
pub text: Option<String>,
pub surname: Option<Vec<u32>>,
pub given: Option<Vec<u32>>,
}
pub trait WordEngine: Send + Sync {
fn id(&self) -> &'static str;
fn name(&self) -> &'static str;
fn compute(&self, q: &WordQuery) -> Result<Value, String>;
fn profile(&self) -> &'static [DetItem] {
&[]
}
}