use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum DvgwMessageType {
Alocat,
Nomint,
Nomres,
Schedl,
Imbnot,
Tranot,
Delord,
Delres,
Chacap,
}
impl DvgwMessageType {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Alocat => "ALOCAT",
Self::Nomint => "NOMINT",
Self::Nomres => "NOMRES",
Self::Schedl => "SCHEDL",
Self::Imbnot => "IMBNOT",
Self::Tranot => "TRANOT",
Self::Delord => "DELORD",
Self::Delres => "DELRES",
Self::Chacap => "CHACAP",
}
}
#[must_use]
pub fn from_unh_code(code: &str) -> Option<Self> {
match code {
"ALOCAT" => Some(Self::Alocat),
"NOMINT" => Some(Self::Nomint),
"NOMRES" => Some(Self::Nomres),
"SCHEDL" => Some(Self::Schedl),
"IMBNOT" => Some(Self::Imbnot),
"TRANOT" => Some(Self::Tranot),
"DELORD" => Some(Self::Delord),
"DELRES" => Some(Self::Delres),
"CHACAP" => Some(Self::Chacap),
_ => None,
}
}
#[must_use]
pub(crate) fn required_feature(self) -> &'static str {
match self {
Self::Alocat => "alocat",
Self::Nomint => "nomint",
Self::Nomres => "nomres",
Self::Schedl => "schedl",
Self::Imbnot => "imbnot",
Self::Tranot => "tranot",
Self::Delord => "delord",
Self::Delres => "delres",
Self::Chacap => "chacap",
}
}
#[must_use]
pub fn synthetic_pid(self, role_qualifier: Option<&str>) -> Option<u32> {
match (self, role_qualifier) {
(Self::Alocat, None | Some("Z15")) => Some(90001),
(Self::Alocat, Some("Z16")) => Some(90002),
(Self::Alocat, Some("Z17")) => Some(90003),
(Self::Nomint, None | Some("Z01")) => Some(90011),
(Self::Nomint, Some("Z02")) => Some(90012),
(Self::Nomres, None | Some("Z01")) => Some(90021),
(Self::Nomres, Some("Z02")) => Some(90022),
(Self::Schedl, _) => Some(90031),
(Self::Imbnot, _) => Some(90041),
(Self::Tranot, _) => Some(90051),
(Self::Delord, _) => Some(90061),
(Self::Delres, _) => Some(90062),
_ => None,
}
}
}
impl fmt::Display for DvgwMessageType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}