use crate::{CliError, Session};
use btctax_adapters::BundledTaxTables;
use btctax_core::defensive::{journey_view, DefensiveFilingView};
use btctax_core::experimental::uses_approach_b;
use btctax_store::Passphrase;
use std::path::Path;
use time::OffsetDateTime;
pub struct DefensiveStatusReport {
pub view: DefensiveFilingView,
pub experimental_notice_active: bool,
}
pub fn status(
vault_path: &Path,
pp: &Passphrase,
now: OffsetDateTime,
) -> Result<DefensiveStatusReport, CliError> {
let session = Session::open(vault_path, pp)?;
let (events, state, cfg) = session.load_events_and_project()?;
if state.pseudo_active() {
return Err(CliError::Usage(
"cannot show defensive-filing status: the ledger is pseudo-reconciled (a synthetic, \
non-persisted default contributes to the projection), which could silently mask a real \
shortfall this command exists to surface. Run `btctax reconcile pseudo off` (or approve + \
attest the pending defaults through `reconcile pseudo approve`) first, then re-run."
.to_string(),
));
}
let tables = BundledTaxTables::load();
let current = now.year();
let view = journey_view(&events, &state, session.prices(), &tables, &cfg, current);
Ok(DefensiveStatusReport {
experimental_notice_active: uses_approach_b(&events),
view,
})
}