use crate::error::Error;
use crate::types::{DeliverBy, DeliverByMode};
pub(crate) const MAX_DELIVER_BY_SECONDS: i128 = 999_999_999;
pub(crate) fn validate_deliver_by_value(deliver_by: &DeliverBy) -> Result<(), Error> {
let magnitude = i128::from(deliver_by.seconds).abs();
if magnitude > MAX_DELIVER_BY_SECONDS {
return Err(Error::Protocol(format!(
"DELIVERBY exceeds the RFC 2852 Section 4 9-digit limit: {}",
deliver_by.seconds
)));
}
if matches!(deliver_by.mode, DeliverByMode::Return) && deliver_by.seconds <= 0 {
return Err(Error::Protocol(format!(
"DELIVERBY by-time must be positive with Return mode: {} \
(RFC 2852 Section 4)",
deliver_by.seconds
)));
}
Ok(())
}