#![cfg_attr(rustfmt, rustfmt::skip)]
use refix_message::{Decimal, GroupTable, Instances, InvalidValue, LazyKnownTags, Tag};
use super::super::enums::{PosQtyStatus, PosType};
use super::NestedParties;
#[derive(Clone, Copy)]
pub struct PositionQty<'a>(refix_message::Scope<'a>);
impl<'a> From<refix_message::Scope<'a>> for PositionQty<'a> {
fn from(scope: refix_message::Scope<'a>) -> Self {
Self(scope)
}
}
impl<'a> PositionQty<'a> {
pub(in super::super) const TABLE: GroupTable<'static> = GroupTable::new(
Tag(702),
Tag(703),
&[Tag(539), Tag(703), Tag(704), Tag(705), Tag(706)],
&[NestedParties::TABLE],
);
pub(in super::super) const fn known_tags() -> &'static LazyKnownTags {
static TAGS: LazyKnownTags = LazyKnownTags::new(
&[Tag(703), Tag(704), Tag(705), Tag(706), Tag(539)],
&[NestedParties::known_tags()],
);
&TAGS
}
pub fn raw(&self) -> refix_message::Scope<'a> {
self.0
}
#[doc(alias = "PosType")]
pub fn pos_type(&self) -> Result<Option<PosType<'a>>, InvalidValue> {
Ok(self.0.get_str(Tag(703))?.map(PosType::from_value))
}
#[doc(alias = "LongQty")]
pub fn long_qty(&self) -> Result<Option<Decimal>, InvalidValue> {
self.0.get_decimal(Tag(704))
}
#[doc(alias = "ShortQty")]
pub fn short_qty(&self) -> Result<Option<Decimal>, InvalidValue> {
self.0.get_decimal(Tag(705))
}
#[doc(alias = "PosQtyStatus")]
pub fn pos_qty_status(&self) -> Result<Option<PosQtyStatus>, InvalidValue> {
Ok(self.0.get_int(Tag(706))?.map(PosQtyStatus::from_value))
}
#[doc(alias = "NoNestedPartyIDs")]
pub fn nested_party_ids(&self) -> Result<Instances<'a, NestedParties<'a>>, InvalidValue> {
self.0.get_group(&NestedParties::TABLE, &Self::known_tags().get()).map(Instances::from)
}
}
impl std::fmt::Debug for PositionQty<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "PositionQty({})", self.0)
}
}