use crate::common::model::{EntityId, PduBody};
use crate::common::{BodyInfo, Interaction};
use crate::enumerations::PduType;
use crate::model::{SupplyQuantity, SUPPLY_QUANTITY_RECORD_LENGTH};
use crate::resupply_received::builder::ResupplyReceivedBuilder;
use crate::BodyRaw;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
const RESUPPLY_RECEIVED_BASE_BODY_LENGTH: u16 = 16;
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ResupplyReceived {
pub requesting_id: EntityId,
pub servicing_id: EntityId,
pub supplies: Vec<SupplyQuantity>,
}
impl BodyRaw for ResupplyReceived {
type Builder = ResupplyReceivedBuilder;
fn builder() -> Self::Builder {
Self::Builder::new()
}
fn into_builder(self) -> Self::Builder {
Self::Builder::new_from_body(self)
}
fn into_pdu_body(self) -> PduBody {
PduBody::ResupplyReceived(self)
}
}
impl BodyInfo for ResupplyReceived {
fn body_length(&self) -> u16 {
RESUPPLY_RECEIVED_BASE_BODY_LENGTH
+ (self.supplies.len() as u16 * SUPPLY_QUANTITY_RECORD_LENGTH)
}
fn body_type(&self) -> PduType {
PduType::ResupplyReceived
}
}
impl Interaction for ResupplyReceived {
fn originator(&self) -> Option<&EntityId> {
Some(&self.requesting_id)
}
fn receiver(&self) -> Option<&EntityId> {
Some(&self.servicing_id)
}
}