#[derive(
    Debug,
    Clone,
    conjure_object::serde::Serialize,
    conjure_object::serde::Deserialize,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash
)]
#[serde(crate = "conjure_object::serde")]
#[conjure_object::private::staged_builder::staged_builder]
#[builder(crate = conjure_object::private::staged_builder, update, inline)]
pub struct EnumBucket {
    #[builder(default, map(key(type = i32), value(type = conjure_object::SafeLong)))]
    #[serde(
        rename = "histogram",
        skip_serializing_if = "std::collections::BTreeMap::is_empty",
        default
    )]
    histogram: std::collections::BTreeMap<i32, conjure_object::SafeLong>,
    #[builder(custom(type = super::CompactEnumPoint, convert = Box::new))]
    #[serde(rename = "firstPoint")]
    first_point: Box<super::CompactEnumPoint>,
    #[builder(
        default,
        custom(
            type = impl
            Into<Option<super::CompactEnumPoint>>,
            convert = |v|v.into().map(Box::new)
        )
    )]
    #[serde(rename = "lastPoint", skip_serializing_if = "Option::is_none", default)]
    last_point: Option<Box<super::CompactEnumPoint>>,
}
impl EnumBucket {
    /// Constructs a new instance of the type.
    #[inline]
    pub fn new(first_point: super::CompactEnumPoint) -> Self {
        Self::builder().first_point(first_point).build()
    }
    /// The map of values within the bucket to their frequency.
    #[inline]
    pub fn histogram(
        &self,
    ) -> &std::collections::BTreeMap<i32, conjure_object::SafeLong> {
        &self.histogram
    }
    #[inline]
    pub fn first_point(&self) -> &super::CompactEnumPoint {
        &*self.first_point
    }
    /// Will be empty if the bucket only has a single point.
    #[inline]
    pub fn last_point(&self) -> Option<&super::CompactEnumPoint> {
        self.last_point.as_ref().map(|o| &**o)
    }
}
