use std::time::{SystemTime, UNIX_EPOCH};

// Get simple timestamp
pub fn get_timestamp() -> Option<u128> {
    actual_get_timestamp(0)
}

// Get timestamp + a TTL
pub fn get_timestamp_with_ttl(ttl_in_seconds: u128) -> Option<u128> {
    actual_get_timestamp(ttl_in_seconds)
}

fn actual_get_timestamp(ttl_in_seconds: u128) -> Option<u128> {
    // Calculate timestamp
    let start = SystemTime::now();
    let epoch = match start.duration_since(UNIX_EPOCH) {
        Ok(since_the_epoch) => since_the_epoch,
        Err(_) => return None,
    };

    let since_the_epoch = epoch.as_micros() + (ttl_in_seconds * 1_000_000);
    return Some(since_the_epoch);
}
