#![cfg_attr(not(windows), allow(dead_code))]

mod capture;

pub use capture::{
    CargoCollectionProbe, CargoCollectionProbeRow, FinanceLogPaths, IndexedCollectionProbe,
    IndexedCollectionProbeRow, sample_finance_snapshot, write_cargo_collection_probe,
    write_finance_snapshot_bundle, write_finance_snapshot_only, write_indexed_collection_probe,
};

#[cfg(windows)]
mod windows;

#[cfg(not(windows))]
pub fn host_build_marker() -> &'static str {
    "rrt-hook host build"
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs;
    use std::time::{SystemTime, UNIX_EPOCH};

    #[test]
    fn writes_snapshot_bundle_to_disk() {
        let nonce = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .expect("system time should be after epoch")
            .as_nanos();
        let dir = std::env::temp_dir().join(format!("rrt-hook-finance-{nonce}"));
        let paths = write_finance_snapshot_bundle(&dir, "testcase", &sample_finance_snapshot())
            .expect("bundle should be written");

        let snapshot_json =
            fs::read_to_string(&paths.snapshot_path).expect("snapshot should exist");
        let outcome_json = fs::read_to_string(&paths.outcome_path).expect("outcome should exist");

        assert!(snapshot_json.contains("\"policy\""));
        assert!(outcome_json.contains("\"evaluation\""));

        let _ = fs::remove_file(&paths.snapshot_path);
        let _ = fs::remove_file(&paths.outcome_path);
        let _ = fs::remove_dir(&dir);
    }
}
