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_offer::builder::ResupplyOfferBuilder;
use crate::BodyRaw;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
const RESUPPLY_OFFER_BASE_BODY_LENGTH: u16 = 16;
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ResupplyOffer {
pub requesting_id: EntityId,
pub servicing_id: EntityId,
pub supplies: Vec<SupplyQuantity>,
}
impl BodyRaw for ResupplyOffer {
type Builder = ResupplyOfferBuilder;
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::ResupplyOffer(self)
}
}
impl BodyInfo for ResupplyOffer {
fn body_length(&self) -> u16 {
RESUPPLY_OFFER_BASE_BODY_LENGTH
+ (self.supplies.len() as u16 * SUPPLY_QUANTITY_RECORD_LENGTH)
}
fn body_type(&self) -> PduType {
PduType::ResupplyOffer
}
}
impl Interaction for ResupplyOffer {
fn originator(&self) -> Option<&EntityId> {
Some(&self.requesting_id)
}
fn receiver(&self) -> Option<&EntityId> {
Some(&self.servicing_id)
}
}