use rand::Rng;

mod connection;
mod error;
mod relayer;
mod subscription;

pub use self::{
    connection::Connection, error::Error, relayer::Relayer, subscription::Subscription,
};

// Get current nanoseconds and use the last 3 digits as a random number (because
// sometimes it comes as 0)
pub(crate) fn get_id() -> u128 {
    let mut rng = rand::thread_rng();
    let random_number = rng.gen_range(0..999);

    let ts = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .expect("time")
        .as_nanos();

    ts.checked_add(random_number).unwrap_or(ts)
}
