use super::super::types::{Item, Kind};
use crate::corpus::Corpus;
use crate::model::stamp;
use crate::model::stamp::days_between;
pub fn run(c: &Corpus, docs: &[usize], out: &mut Vec<Item>) {
let today = stamp::today();
let a = &c.cfg.raw.audit;
for &i in docs {
let d = &c.docs[i];
let status = d.status().unwrap_or_default();
let (limit, what) = match (d.id.ty.as_str(), status.as_str()) {
("plan", "active") => {
if let Some(review_by) = d.str_field("review_by")
&& let Some(day) = stamp::utc_day(&review_by)
{
if day >= today {
continue;
}
out.push(Item {
kind: Kind::Stalled,
subject: d.id.to_string(),
path: d.path.clone(),
line: 1,
detail: format!("active plan was due for review on {review_by}"),
next: Some(format!(
"spec set {} review_by=<YYYY-MM-DD> --write # or {}",
crate::suggest::shell::word(&d.id),
super::archive(c, i)
)),
});
continue;
}
(a.stalled_days, "active plan has no update")
}
(_, "draft") => (a.draft_days, "draft not decided"),
_ => continue,
};
let Some(updated) = d.str_field("updated") else { continue };
let Some(age) = days_between(&updated, &today) else { continue };
if age > limit {
out.push(Item {
kind: Kind::Stalled,
subject: d.id.to_string(),
path: d.path.clone(),
line: 1,
detail: format!("{what} for {age} days (since {updated})"),
next: Some(format!(
"{} # or record progress and spec set {} updated=today --write",
super::archive(c, i),
crate::suggest::shell::word(&d.id)
)),
});
}
}
}