use dat::crypt::CryptAlgorithm::{AES128GCMN, AES256GCMN};
use dat::dat_key::DatKey;
use dat::sign::SignAlgorithm::{P256, P384, P521};
use dat::util::now_unix_timestamp;
use rand::RngExt;
use std::time::Instant;

fn rand_string() -> String {
    let mut rng = rand::rng();
    (0..100).map(|_| { rng.sample(rand::distr::Alphanumeric) as char }).collect()
}

#[test]
fn test() {
    let plain = rand_string();
    let secure = rand_string();

    println!("performance test (plain, secure)");
    println!("plain: {}", plain);
    println!("secure: {}", secure);

    let sign_alg_arr = [P256, P384, P521];
    let crypt_alg_arr = [AES128GCMN, AES256GCMN];

    sign_alg_arr.iter().for_each(|sign_alg| {
        crypt_alg_arr.iter().for_each(|crypt_alg| {
            let key = DatKey::<i64>::generate(0, *sign_alg, *crypt_alg, now_unix_timestamp() - 10, now_unix_timestamp() + 600, 60).unwrap().active().unwrap();
            let start = Instant::now();
            let mut dat: String = "".to_string();
            (1..1000).for_each(|_| {
                dat = key.to_dat(&plain, &secure).unwrap();
            });
            let duration = start.elapsed(); // 경과 시간 계산
            println!("{}/{} to_dat * 1000 : {}ms", sign_alg.to_str(), crypt_alg.to_str(), duration.as_millis());
            let start = Instant::now();
            (1..1000).for_each(|_| {
                key.to_payload(&dat).unwrap();
            });
            let duration = start.elapsed(); // 경과 시간 계산
            println!("{}/{} to_payload * 1000 : {}ms", sign_alg.to_str(), crypt_alg.to_str(), duration.as_millis());
        });
    });
}