//! Utility functions for the SDK

/// debug print queries generated by diesel for the postgres backend
///
/// # Example
///
/// ```ignore
/// use diesel::prelude::*;
///
/// diesel::table! {
///     use diesel::sql_types::*;
///
///     user (id) {
///         id -> Int8,
///         name -> Text,
///     }
/// }
///
/// let conn = ft_sdk::default_pg().unwrap();
///
/// let query = user::table
///     .select(user::name)
///     .filter(user::id.eq(9))
///     .limit(1);
///
/// ft_sdk::utils::dbg_query(&query);
/// ```
pub fn dbg_query<T: diesel::query_builder::QueryFragment<B>, B: diesel::backend::Backend>(
    _query: &T,
) {
    #[cfg(feature = "debug")]
    ft_sdk::println!("{:?}", diesel::debug_query::<B, _>(_query));
}

/// Generate a new uuid v8 using the uuid crate
pub fn uuid_v8() -> String {
    use rand_core::RngCore;

    let mut rand_buf: [u8; 16] = Default::default();
    ft_sdk::Rng::fill_bytes(&mut ft_sdk::Rng {}, &mut rand_buf);
    uuid::Uuid::new_v8(rand_buf).to_string()
}
