use chrono::{NaiveDateTime, TimeDelta, Utc};
use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};

pub fn generate_token_and_expiration(token_length_bytes: usize, validity: TimeDelta) -> (String, NaiveDateTime) {
        let value = std::iter::repeat(())
            .map(|()| OsRng.sample(Alphanumeric))
            .take(token_length_bytes)
            .collect::<Vec<_>>();

        let token = String::from_utf8(value).unwrap().try_into().unwrap();

        let expires = Utc::now().naive_utc() + validity;

        return (token, expires);
}
