use crate::loader::Journal;
pub fn enrich(journal: &mut Journal, target: Option<&str>, unrealized: bool) {
crate::expander::expand(&mut journal.transactions, &journal.auto_rules);
if let (Some(t), Some(gain), Some(loss)) =
(target, journal.fx_realized_gain.as_deref(), journal.fx_realized_loss.as_deref())
{
crate::realizer::realize(
&mut journal.transactions,
t,
&journal.prices,
&journal.precisions,
gain,
loss,
);
}
if let (Some(cg), Some(cl)) =
(journal.capital_gain.as_deref(), journal.capital_loss.as_deref())
{
let accounts = crate::lotter::CapitalAccounts {
capital_gain: cg,
capital_loss: cl,
};
crate::lotter::realize_capital(
&mut journal.transactions,
&accounts,
target,
&journal.prices,
&journal.precisions,
);
}
if let (Some(t), Some(cta_gain), Some(cta_loss)) =
(target, journal.cta_gain.as_deref(), journal.cta_loss.as_deref())
{
let precision = journal.precisions.get(t).copied().unwrap_or(2);
crate::translator::translate(
&mut journal.transactions,
t,
&journal.prices,
cta_gain,
cta_loss,
precision,
);
}
if let (Some(t), true, Some(rg), Some(rl)) = (
target,
unrealized,
journal.fx_unrealized_gain.as_deref(),
journal.fx_unrealized_loss.as_deref(),
) {
let precision = journal.precisions.get(t).copied().unwrap_or(2);
crate::revaluator::revaluate(
&mut journal.transactions,
t,
&journal.prices,
&crate::revaluator::RevaluationAccounts { gain: rg, loss: rl },
precision,
);
}
}