use bacnet_objects::event::EventStateChange;
use bacnet_types::enums::EventType;
use bacnet_types::primitives::BACnetTimeStamp;
use super::super::event_notification_payload::CommittedNotificationPayload;
use super::super::event_timestamp::SampledEventClock;
#[derive(Debug, Clone, PartialEq)]
pub(in crate::server) struct CommittedHistorySnapshot {
pub(in crate::server) timestamp: BACnetTimeStamp,
pub(in crate::server) message_text: Option<String>,
}
pub(in crate::server) enum NotificationHistorySource {
SendTime,
Committed {
snapshot: CommittedHistorySnapshot,
recipient_clock: SampledEventClock,
},
}
pub(in crate::server) enum NotificationConstruction {
Event,
Acknowledgment,
}
pub(in crate::server) struct NotificationTransition {
pub(in crate::server) change: EventStateChange,
pub(in crate::server) event_type: EventType,
pub(in crate::server) history_source: NotificationHistorySource,
pub(in crate::server) ack_required: Option<bool>,
pub(in crate::server) event_values: Option<CommittedNotificationPayload>,
pub(in crate::server) construction: NotificationConstruction,
}
impl NotificationTransition {
pub(in crate::server) fn acknowledgment(
change: EventStateChange,
event_type: EventType,
) -> Self {
Self {
change,
event_type,
history_source: NotificationHistorySource::SendTime,
ack_required: Some(false),
event_values: None,
construction: NotificationConstruction::Acknowledgment,
}
}
}
impl From<(EventStateChange, EventType)> for NotificationTransition {
fn from((change, event_type): (EventStateChange, EventType)) -> Self {
Self {
change,
event_type,
history_source: NotificationHistorySource::SendTime,
ack_required: None,
event_values: None,
construction: NotificationConstruction::Event,
}
}
}
pub(in crate::server) struct CommittedIntrinsicTransition {
pub(in crate::server) change: EventStateChange,
pub(in crate::server) event_type: EventType,
pub(in crate::server) distribute: bool,
pub(in crate::server) history_snapshot: CommittedHistorySnapshot,
pub(in crate::server) recipient_clock: SampledEventClock,
pub(in crate::server) ack_required: bool,
pub(in crate::server) event_values: Option<CommittedNotificationPayload>,
}
impl From<CommittedIntrinsicTransition> for NotificationTransition {
fn from(committed: CommittedIntrinsicTransition) -> Self {
Self {
change: committed.change,
event_type: committed.event_type,
history_source: NotificationHistorySource::Committed {
snapshot: committed.history_snapshot,
recipient_clock: committed.recipient_clock,
},
ack_required: Some(committed.ack_required),
event_values: committed.event_values,
construction: NotificationConstruction::Event,
}
}
}