#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{Instances, InvalidValue, LazyKnownTags, RawMessage, Tag, UtcTimestamp};
use super::super::components::{Header, SettlInstGrp, Trailer};
use super::super::enums::{SettlInstMode, SettlInstReqRejCode};
pub struct SettlementInstructions(RawMessage);
impl SettlementInstructions {
pub const MSG_TYPE: &[u8] = b"T";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(777), Tag(791), Tag(160), Tag(792), Tag(58), Tag(354), Tag(355), Tag(11),
Tag(60), Tag(778),
],
&[Header::known_tags(), Trailer::known_tags(), SettlInstGrp::known_tags()],
);
&TAGS
}
pub fn from_raw(raw: RawMessage) -> Self {
Self(raw)
}
pub fn raw(&self) -> &RawMessage {
&self.0
}
pub fn header(&self) -> Header<'_> {
Header(self.0.scope(), Self::known_tags().get())
}
pub fn trailer(&self) -> Trailer<'_> {
Trailer(self.0.scope())
}
#[doc(alias = "SettlInstMsgID")]
pub fn settl_inst_msg_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(777))
}
#[doc(alias = "SettlInstReqID")]
pub fn settl_inst_req_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(791))
}
#[doc(alias = "SettlInstMode")]
pub fn settl_inst_mode(&self) -> Result<Option<SettlInstMode<'_>>, InvalidValue> {
Ok(self.0.get_str(Tag(160))?.map(SettlInstMode::from_value))
}
#[doc(alias = "SettlInstReqRejCode")]
pub fn settl_inst_req_rej_code(&self) -> Result<Option<SettlInstReqRejCode>, InvalidValue> {
Ok(self.0.get_int(Tag(792))?.map(SettlInstReqRejCode::from_value))
}
#[doc(alias = "Text")]
pub fn text(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(58))
}
#[doc(alias = "EncodedTextLen")]
pub fn encoded_text_len(&self) -> Result<Option<i64>, InvalidValue> {
self.0.get_int(Tag(354))
}
#[doc(alias = "EncodedText")]
pub fn encoded_text(&self) -> Option<&[u8]> {
self.0.get(Tag(355))
}
#[doc(alias = "ClOrdID")]
pub fn cl_ord_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(11))
}
#[doc(alias = "TransactTime")]
pub fn transact_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
self.0.get_utc_timestamp(Tag(60))
}
#[doc(alias = "NoSettlInst")]
pub fn settl_inst(&self) -> Result<Instances<'_, SettlInstGrp<'_>>, InvalidValue> {
self.0.get_group(&SettlInstGrp::TABLE, &Self::known_tags().get()).map(Instances::from)
}
}
impl std::fmt::Debug for SettlementInstructions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SettlementInstructions({})", self.0)
}
}
impl std::fmt::Display for SettlementInstructions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}