use athena_rs::api::metrics::MetricsState;
use criterion::{Criterion, criterion_group, criterion_main};

fn bench_http_recording(c: &mut Criterion) {
    let state = MetricsState::new();
    let mut index: u64 = 0;

    c.bench_function("record_http_metrics_hot_path", |b| {
        b.iter(|| {
            let method = if index.is_multiple_of(2) {
                "GET"
            } else {
                "POST"
            };
            let route = if index.is_multiple_of(3) {
                "/gateway/data"
            } else if index % 3 == 1 {
                "/management/clients"
            } else {
                "/schema/tables"
            };
            let status = match index % 5 {
                0 => 200,
                1 => 204,
                2 => 400,
                3 => 404,
                _ => 500,
            };

            state.begin_http_request(method, route);
            state.finish_http_request(
                method,
                route,
                status,
                (index % 1000) as f64 / 1000.0,
                Some(128 + (index % 2048)),
                Some(256 + (index % 4096)),
                Some("athena_logging"),
            );

            if index.is_multiple_of(17) {
                state.record_http_handler_error(
                    method,
                    route,
                    (index % 1000) as f64 / 1000.0,
                    Some(128 + (index % 2048)),
                    Some("athena_logging"),
                );
            }

            state.record_management_mutation(
                if index.is_multiple_of(2) {
                    "create_index"
                } else {
                    "drop_index"
                },
                if index.is_multiple_of(5) {
                    "error"
                } else {
                    "success"
                },
                (index % 500) as f64 / 1000.0,
            );

            index = index.wrapping_add(1);
        })
    });
}

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