Skip to main content

btctax_cli/cmd/
import.rs

1//! `import <files…>` (FR1/FR2) — detect+parse via adapters, append the batch atomically into the
2//! vault, and save. Idempotency + `ImportConflict` detection are core's job (`append_import_batch`);
3//! the CLI surfaces the per-source FR2 counts (dropped/unclassified) and the append/dup/conflict tally.
4use crate::{CliError, Session};
5use btctax_adapters::{ingest_files_bundled, FileReport};
6use btctax_core::persistence::{append_import_batch, ImportReport};
7use btctax_store::Passphrase;
8use std::path::{Path, PathBuf};
9
10pub fn run(
11    vault_path: &Path,
12    pp: &Passphrase,
13    files: &[PathBuf],
14) -> Result<(Vec<FileReport>, ImportReport), CliError> {
15    let batch = ingest_files_bundled(files)?; // adapters: detect→group→parse→normalize (FR2/FR3)
16    let mut session = Session::open(vault_path, pp)?;
17    let import = append_import_batch(session.conn(), &batch.events)?; // ATOMIC batch (FR1)
18    session.save()?; // encrypted, atomic (NFR2/NFR3)
19    Ok((batch.reports, import))
20}