use crate::unit_newtype;

/// Oxygen Tolerance Unit accumulation rate in $\text{OTU/min}$.
///
/// Computed via the NOAA formula:
/// $$
/// \text{OTU/min} = \left(\text{pp}\ce{O2} - \pu{0.5 bar}\right)^{0.83}
/// \quad \text{when } \text{pp}\ce{O2} > \pu{0.5 bar}, \text{ else } 0
/// $$
/// The daily limit is approximately $\pu{850 OTU}$.
///
/// ```
/// # use approx::assert_relative_eq;
/// use dps_units::OTUPerMinute;
///
/// let rate = OTUPerMinute::new(0.918);
/// assert_eq!(rate, OTUPerMinute::new(0.918));
/// assert_eq!(rate.to_string(), "0.9 OTU/min");
///
/// assert_relative_eq!(rate + OTUPerMinute::new(0.082), OTUPerMinute::new(1.0));
/// assert_relative_eq!(rate - OTUPerMinute::new(0.082), OTUPerMinute::new(0.836));
/// assert_relative_eq!(rate * 60.0, OTUPerMinute::new(0.918 * 60.0));
/// assert_relative_eq!(rate / 2.0, OTUPerMinute::new(0.459));
///
/// // Ratio between two rates is dimensionless.
/// let ratio: f64 = OTUPerMinute::new(2.0) / OTUPerMinute::new(1.0);
/// assert_relative_eq!(ratio, 2.0);
///
/// assert_relative_eq!(-rate, OTUPerMinute::new(-0.918));
/// assert_relative_eq!(2.0_f64 * rate, OTUPerMinute::new(1.836));
/// assert_eq!(rate.max(OTUPerMinute::new(1.0)), OTUPerMinute::new(1.0));
/// ```
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
pub struct OTUPerMinute(f64);

unit_newtype!(OTUPerMinute, "OTU/min");
