#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{Date, InvalidValue, LazyKnownTags, RawMessage, Tag, UtcTimestamp};
use super::super::components::{Header, Trailer};
use super::super::enums::{AffirmStatus, ConfirmRejReason, MatchStatus};
pub struct ConfirmationAck(RawMessage);
impl ConfirmationAck {
pub const MSG_TYPE: &[u8] = b"AU";
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[
Tag(664), Tag(75), Tag(60), Tag(940), Tag(774), Tag(573), Tag(58), Tag(354),
Tag(355),
],
&[Header::known_tags(), Trailer::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 = "ConfirmID")]
pub fn confirm_id(&self) -> Result<Option<&str>, InvalidValue> {
self.0.get_str(Tag(664))
}
#[doc(alias = "TradeDate")]
pub fn trade_date(&self) -> Result<Option<Date>, InvalidValue> {
self.0.get_date(Tag(75))
}
#[doc(alias = "TransactTime")]
pub fn transact_time(&self) -> Result<Option<UtcTimestamp>, InvalidValue> {
self.0.get_utc_timestamp(Tag(60))
}
#[doc(alias = "AffirmStatus")]
pub fn affirm_status(&self) -> Result<Option<AffirmStatus>, InvalidValue> {
Ok(self.0.get_int(Tag(940))?.map(AffirmStatus::from_value))
}
#[doc(alias = "ConfirmRejReason")]
pub fn confirm_rej_reason(&self) -> Result<Option<ConfirmRejReason>, InvalidValue> {
Ok(self.0.get_int(Tag(774))?.map(ConfirmRejReason::from_value))
}
#[doc(alias = "MatchStatus")]
pub fn match_status(&self) -> Result<Option<MatchStatus<'_>>, InvalidValue> {
Ok(self.0.get_str(Tag(573))?.map(MatchStatus::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))
}
}
impl std::fmt::Debug for ConfirmationAck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ConfirmationAck({})", self.0)
}
}
impl std::fmt::Display for ConfirmationAck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}