use crate::db::models::GoalState;
use crate::utils::string::humanize_age;
pub const DRIVER_STALE_AFTER_SECS: i64 = 3600;
pub fn driver_line(goal: &GoalState) -> String {
let turns = format!("Turns: {}/{}", goal.turns_used, goal.max_turns);
if goal.turns_used == 0 {
return match goal.state.as_str() {
"active" => format!(
"{turns} — never evaluated; armed but not driving \
(nothing starts a turn for a goal)"
),
_ => format!("{turns} — never evaluated"),
};
}
match age_secs(&goal.updated_at) {
Some(age) if goal.state == "active" && age > DRIVER_STALE_AFTER_SECS => format!(
"{turns} — ⚠️ no goal activity for {}; nothing re-evaluates this \
goal until a turn runs here",
humanize_age(age)
),
Some(age) => format!("{turns} — last activity {} ago", humanize_age(age)),
None => turns,
}
}
fn age_secs(stamp: &str) -> Option<i64> {
let then = chrono::DateTime::parse_from_rfc3339(stamp).ok()?;
Some(
chrono::Utc::now()
.signed_duration_since(then)
.num_seconds()
.max(0),
)
}