use std::fmt;

/// Percentile statistics for a histogram.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PercentileStats {
    /// Number of samples recorded
    pub samples: u64,
    /// 0.1th percentile (99.9% of values >= this)
    pub p0_1: u64,
    /// 1st percentile (99% of values >= this)
    pub p1: u64,
    /// 5th percentile (95% of values >= this)
    pub p5: u64,
    /// 10th percentile (90% of values >= this)
    pub p10: u64,
    /// 50th percentile (median)
    pub p50: u64,
    /// 90th percentile
    pub p90: u64,
    /// 99th percentile
    pub p99: u64,
    /// 99.9th percentile
    pub p99_9: u64,
}

impl fmt::Display for PercentileStats {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "[samples: {}, P0.1: {}, P1: {}, P5: {}, P10: {}, P50: {}, P90: {}, P99: {}, P99.9: {}]",
            self.samples, self.p0_1, self.p1, self.p5, self.p10, self.p50, self.p90, self.p99, self.p99_9
        )
    }
}
