use hdk::prelude::*;
pub fn get_details(
links: Vec<Link>,
option: GetOptions,
) -> ExternResult<Vec<(Details, Link, ActionHash)>> {
let links: Vec<(AnyDhtHash, Link)> = links
.iter()
.filter_map(|l| match l.clone().target.into_entry_hash() {
Some(e) => Some((e.into(), l.clone())),
None => l
.clone()
.target
.into_action_hash()
.map(|a| (a.into(), l.clone())),
})
.collect();
let msg_results_input: Vec<GetInput> = links
.clone()
.into_iter()
.map(|link| GetInput::new(link.0, option.clone()))
.collect();
let list = HDK.with(|hdk| hdk.borrow().get_details(msg_results_input))?;
Ok(list
.iter()
.filter_map(|d| match d {
Some(details) => {
if let Details::Record(r) = details {
let action_hash = r.record.action_address().clone();
let any_hash: AnyDhtHash = action_hash.clone().into();
let found = links
.iter()
.find_map(|(h, l)| if h == &any_hash { Some(l) } else { None });
found.map(|l| (details.clone(), l.clone(), action_hash))
} else {
None
}
}
None => None,
})
.collect())
}