use std::collections::HashSet;
use std::error::Error;
use std::time::Duration;
use p2panda_core::Topic;
pub trait NodeInfo<ID> {
type Transports;
fn id(&self) -> ID;
fn is_bootstrap(&self) -> bool;
fn is_stale(&self) -> bool;
fn transports(&self) -> Option<Self::Transports>;
}
pub trait AddressBookStore<ID, N>
where
N: NodeInfo<ID>,
{
type Error: Error;
fn insert_node_info(&self, info: N) -> impl Future<Output = Result<bool, Self::Error>>;
fn remove_node_info(&self, id: &ID) -> impl Future<Output = Result<bool, Self::Error>>;
fn remove_older_than(
&self,
duration: Duration,
) -> impl Future<Output = Result<usize, Self::Error>>;
fn node_info(&self, id: &ID) -> impl Future<Output = Result<Option<N>, Self::Error>>;
fn node_topics(&self, id: &ID) -> impl Future<Output = Result<HashSet<Topic>, Self::Error>>;
fn all_node_infos(&self) -> impl Future<Output = Result<Vec<N>, Self::Error>>;
fn all_nodes_len(&self) -> impl Future<Output = Result<usize, Self::Error>>;
fn all_bootstrap_nodes_len(&self) -> impl Future<Output = Result<usize, Self::Error>>;
fn selected_node_infos(&self, ids: &[ID]) -> impl Future<Output = Result<Vec<N>, Self::Error>>;
fn set_topics(
&self,
id: ID,
topics: HashSet<Topic>,
) -> impl Future<Output = Result<(), Self::Error>>;
fn node_infos_by_topics(
&self,
topics: &[Topic],
) -> impl Future<Output = Result<Vec<N>, Self::Error>>;
fn random_node(&self) -> impl Future<Output = Result<Option<N>, Self::Error>>;
fn random_bootstrap_node(&self) -> impl Future<Output = Result<Option<N>, Self::Error>>;
}