use serde::{Deserialize, Serialize};
use super::state::{Observation, Version};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LifecycleEvent {
Created { v: Version },
Ready { v: Version },
TurnStarted { v: Version },
TurnEnded { v: Version },
Heartbeat { v: Version, body: Observation },
Complete { v: Version },
IntentPending { v: Version },
IntentRetry { v: Version },
IntentReceipt { v: Version },
IntentExhausted { v: Version },
ResourceAttach { v: Version },
ResourceCloseRequested { v: Version },
ResourceClosed { v: Version },
Suspend { v: Version },
Resume { v: Version },
AgentGone { v: Version },
Cancel { v: Version },
Fail { v: Version },
ReconcileMismatch { v: Version },
ReconcileOk { v: Version },
AdoptNewGeneration { v: Version },
Supersede {
v: Version,
old_generation_dead: bool,
body: Observation,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Verdict {
Applied(Observation),
Ignored(IgnoredReason),
Rejected(RejectReason),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IgnoredReason {
StaleGeneration,
StaleOrDuplicateSeq,
NoOp,
GenerationFinished,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RejectReason {
DuplicateLiveGeneration,
UnadoptedGeneration,
OldGenerationLive,
IllegalObservation,
UndefinedTransition,
}
pub fn event_version(event: &LifecycleEvent) -> Version {
match event {
LifecycleEvent::Created { v }
| LifecycleEvent::Ready { v }
| LifecycleEvent::TurnStarted { v }
| LifecycleEvent::TurnEnded { v }
| LifecycleEvent::Heartbeat { v, .. }
| LifecycleEvent::Complete { v }
| LifecycleEvent::IntentPending { v }
| LifecycleEvent::IntentRetry { v }
| LifecycleEvent::IntentReceipt { v }
| LifecycleEvent::IntentExhausted { v }
| LifecycleEvent::ResourceAttach { v }
| LifecycleEvent::ResourceCloseRequested { v }
| LifecycleEvent::ResourceClosed { v }
| LifecycleEvent::Suspend { v }
| LifecycleEvent::Resume { v }
| LifecycleEvent::AgentGone { v }
| LifecycleEvent::Cancel { v }
| LifecycleEvent::Fail { v }
| LifecycleEvent::ReconcileMismatch { v }
| LifecycleEvent::ReconcileOk { v }
| LifecycleEvent::AdoptNewGeneration { v }
| LifecycleEvent::Supersede { v, .. } => *v,
}
}