//! Network profiling module

use super::error::ProfilingError;

pub mod bandwidth;
pub mod iperf;
pub mod jitter;
pub mod latency;
pub mod protocol;
pub mod rhai;
pub mod throughput;

pub use bandwidth::{
    BandwidthResult, measure_bandwidth, measure_bandwidth_download, measure_bandwidth_upload,
};
pub use iperf::{IperfClient, IperfConfig, IperfResult, is_iperf3_available};
pub use jitter::{JitterResult, run_jitter_test};
pub use latency::{LatencyResult, measure_latency};
pub use protocol::Protocol;
pub use throughput::{ThroughputResult, test_udp_throughput};

/// Parameterized network benchmark functions
pub fn benchmark_network_bandwidth(
    server: &str,
    duration_sec: i64,
) -> Result<BandwidthResult, ProfilingError> {
    measure_bandwidth(server, std::time::Duration::from_secs(duration_sec as u64))
}

pub fn benchmark_network_latency(host: &str, count: i64) -> Result<LatencyResult, ProfilingError> {
    measure_latency(host, count.max(0).min(100) as u32) // Clamp to valid range and use u32
}

pub fn benchmark_network_jitter(server: &str) -> Result<JitterResult, ProfilingError> {
    run_jitter_test(server)
}

pub fn benchmark_network_udp_throughput(
    server: &str,
    bandwidth_bps: i64,
) -> Result<ThroughputResult, ProfilingError> {
    test_udp_throughput(server, bandwidth_bps as u64)
}

#[cfg(test)]
mod network_tests;
