use serde::Serialize;
use crate::model::{
RequestValidationError, ValidateRequest, non_empty, one_of, optional_unsigned_integer_string,
range_u64,
};
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct MassCancelRequest {
pub inst_type: String,
pub inst_family: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub lock_interval: Option<String>,
}
impl MassCancelRequest {
pub fn option(inst_family: impl Into<String>) -> Self {
Self {
inst_type: "OPTION".to_owned(),
inst_family: inst_family.into(),
lock_interval: None,
}
}
pub fn lock_interval(mut self, lock_interval: impl Into<String>) -> Self {
self.lock_interval = Some(lock_interval.into());
self
}
}
impl ValidateRequest for MassCancelRequest {
fn validate(&self) -> Result<(), RequestValidationError> {
one_of("instType", &self.inst_type, &["OPTION"], "OPTION")?;
non_empty("instFamily", &self.inst_family)?;
optional_unsigned_integer_string("lockInterval", self.lock_interval.as_deref())?;
if let Some(value) = self.lock_interval.as_deref() {
let value =
value
.parse::<u64>()
.map_err(|_| RequestValidationError::InvalidFormat {
field: "lockInterval",
expected: "an integer from 0 through 10000",
})?;
range_u64("lockInterval", value, 0, 10_000)?;
}
Ok(())
}
}