use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mimic_rs::{Brand, ClientHints, Platform};

fn bench_parse_chrome_windows(c: &mut Criterion) {
    let ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.129 Safari/537.36";

    c.bench_function("parse_chrome_windows", |b| {
        b.iter(|| ClientHints::from_ua(black_box(ua)))
    });
}

fn bench_parse_edge(c: &mut Criterion) {
    let ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.2210.91";

    c.bench_function("parse_edge", |b| {
        b.iter(|| ClientHints::from_ua(black_box(ua)))
    });
}

fn bench_parse_android(c: &mut Criterion) {
    let ua = "Mozilla/5.0 (Linux; Android 13; SM-G998B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.129 Mobile Safari/537.36";

    c.bench_function("parse_android", |b| {
        b.iter(|| ClientHints::from_ua(black_box(ua)))
    });
}

fn bench_generate_sec_ch_ua(c: &mut Criterion) {
    let hints = ClientHints::new(Brand::Chrome, 120, "120.0.0.0", Platform::Windows, false);

    c.bench_function("generate_sec_ch_ua", |b| {
        b.iter(|| black_box(&hints).sec_ch_ua())
    });
}

fn bench_generate_full_version_list(c: &mut Criterion) {
    let hints = ClientHints::new(Brand::Chrome, 120, "120.0.6099.129", Platform::Windows, false);

    c.bench_function("generate_full_version_list", |b| {
        b.iter(|| black_box(&hints).sec_ch_ua_full_version_list())
    });
}

fn bench_all_headers(c: &mut Criterion) {
    let hints = ClientHints::new(Brand::Chrome, 120, "120.0.0.0", Platform::Windows, false);

    c.bench_function("all_headers", |b| {
        b.iter(|| black_box(&hints).all_headers())
    });
}

fn bench_parse_and_generate(c: &mut Criterion) {
    let ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.129 Safari/537.36";

    c.bench_function("parse_and_generate", |b| {
        b.iter(|| {
            let hints = ClientHints::from_ua(black_box(ua)).unwrap();
            hints.sec_ch_ua()
        })
    });
}

criterion_group!(
    benches,
    bench_parse_chrome_windows,
    bench_parse_edge,
    bench_parse_android,
    bench_generate_sec_ch_ua,
    bench_generate_full_version_list,
    bench_all_headers,
    bench_parse_and_generate
);

criterion_main!(benches);
