use armour::types::{
    enc::{Cipher, IdHasher},
    fuid::Fuid,
    low_id::LowId,
};
use blowfish_rs::Blowfish;
use const_decoder::Decoder;
use criterion::{Criterion, criterion_group, criterion_main};
use rand::{Rng, rng};

#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash)]
pub struct Hasher;

impl IdHasher for Hasher {
    const HASHER: Cipher = {
        let bytes: [u8; 16] = Decoder::Base64Url.decode(b"U83jDuBoZGoeWHhLDz0zbg");
        let bf = Blowfish::new_from_slice(&bytes);
        let bf = match bf {
            Ok(bf) => bf,
            Err(_) => panic!("failed to create blowfish"),
        };
        Cipher::raw(bf)
    };
}

pub fn gen_fuids(c: &mut Criterion) {
    c.bench_function("gen fuid's", |b| {
        b.iter(|| {
            let mut rng = rng();
            let app_id: u64 = rng.random_range(0..8);
            let thread_id = rng.random_range(0..32);
            let _ = Fuid::<Hasher>::with_shard_thread(app_id, thread_id);
        })
    });

    c.bench_function("gen low_id's", |b| {
        b.iter(|| {
            let mut rng = rng();
            let app_id: u64 = rng.random_range(0..8);
            let thread_id = rng.random_range(0..32);
            let _ = LowId::<Hasher>::with_shard_thread(app_id, thread_id);
        })
    });
}

criterion_group!(benches, gen_fuids);
criterion_main!(benches);
