#![allow(clippy::uninlined_format_args)]

// Helper method to format bytes in human-readable form
pub fn bytes2hr(bytes: usize) -> String {
    if bytes < 1024 {
        format!("{bytes} bytes")
    } else if bytes < 1024 * 1024 {
        format!("{:.2} KB", bytes as f64 / 1024.0)
    } else if bytes < 1024 * 1024 * 1024 {
        format!("{:.2} MB", bytes as f64 / (1024.0 * 1024.0))
    } else {
        format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
    }
}

pub fn bits2hr(bits: usize) -> String {
    let bytes = bits as f64 / 8.0; // Convert bits to bytes
    if bytes < 1024.0 {
        format!("{:.2} bytes", bytes) // Show actual bytes
    } else if bytes < 1024.0 * 1024.0 {
        format!("{:.2} KB", bytes / 1024.0) // KB = bytes / 1024
    } else if bytes < 1024.0 * 1024.0 * 1024.0 {
        format!("{:.2} MB", bytes / (1024.0 * 1024.0)) // MB = bytes / (1024²)
    } else {
        format!("{:.2} GB", bytes / (1024.0 * 1024.0 * 1024.0)) // GB = bytes / (1024³)
    }
}
