use chrono::NaiveDate;
use datasynth_core::models::{CovenantType, DebtCovenant, JournalEntry};
use rust_decimal::Decimal;
use std::collections::HashMap;
#[derive(Debug, Default)]
pub struct CovenantEvaluationResult {
pub all_compliant: bool,
pub breached_covenants: Vec<String>,
pub breach_jes: Vec<JournalEntry>,
}
pub struct CovenantEvaluator;
impl CovenantEvaluator {
pub fn evaluate_covenants(
covenants: &mut [DebtCovenant],
actual_ratios: &HashMap<CovenantType, Decimal>,
measurement_date: NaiveDate,
) -> CovenantEvaluationResult {
let mut breached_covenants: Vec<String> = Vec::new();
for covenant in covenants.iter_mut() {
if let Some(&actual_value) = actual_ratios.get(&covenant.covenant_type) {
covenant.actual_value = actual_value;
covenant.measurement_date = measurement_date;
covenant.update_compliance();
if !covenant.is_compliant {
breached_covenants.push(covenant.id.clone());
}
}
}
let all_compliant = breached_covenants.is_empty();
CovenantEvaluationResult {
all_compliant,
breached_covenants,
breach_jes: Vec::new(), }
}
}