use super::walk::{GraphWalk, SqlNeighbors};
use crate::errors::AppError;
use rusqlite::Connection;
pub type EntityDepthMap = std::collections::HashMap<i64, u32>;
pub type PredecessorMap = std::collections::HashMap<i64, (i64, String, f64)>;
pub fn bfs_with_predecessors(
conn: &Connection,
seed_entity_ids: &[i64],
namespace: &str,
min_weight: f64,
max_hops: u32,
max_neighbors_per_hop: Option<usize>,
) -> Result<(EntityDepthMap, PredecessorMap), AppError> {
let walk = GraphWalk::directed(min_weight, max_hops).with_neighbor_cap(max_neighbors_per_hop);
let outcome = walk.run(&SqlNeighbors::new(conn, namespace), seed_entity_ids)?;
let predecessor: PredecessorMap = outcome
.arrival
.into_iter()
.map(|(id, edge)| (id, (edge.from_id, edge.relation, edge.weight)))
.collect();
Ok((outcome.depth, predecessor))
}