use crate::proto::common::metrics::Bounds as PbBounds;
use crate::quantity::{Current, Power, Quantity, ReactivePower};
pub struct Bounds<Q: Quantity> {
lower: Option<Q>,
upper: Option<Q>,
}
impl<Q: Quantity> Bounds<Q> {
pub fn new(lower: Option<Q>, upper: Option<Q>) -> Self {
Self { lower, upper }
}
pub fn lower(&self) -> Option<Q> {
self.lower
}
pub fn upper(&self) -> Option<Q> {
self.upper
}
}
impl<Q: Quantity> From<(Option<Q>, Option<Q>)> for Bounds<Q> {
fn from(bounds: (Option<Q>, Option<Q>)) -> Self {
Self::new(bounds.0, bounds.1)
}
}
impl From<Bounds<Power>> for PbBounds {
fn from(bounds: Bounds<Power>) -> Self {
PbBounds {
lower: bounds.lower.map(|q| q.as_watts()),
upper: bounds.upper.map(|q| q.as_watts()),
}
}
}
impl From<Bounds<Current>> for PbBounds {
fn from(bounds: Bounds<Current>) -> Self {
PbBounds {
lower: bounds.lower.map(|q| q.as_amperes()),
upper: bounds.upper.map(|q| q.as_amperes()),
}
}
}
impl From<Bounds<ReactivePower>> for PbBounds {
fn from(bounds: Bounds<ReactivePower>) -> Self {
PbBounds {
lower: bounds.lower.map(|q| q.as_volt_amperes_reactive()),
upper: bounds.upper.map(|q| q.as_volt_amperes_reactive()),
}
}
}