Skip to main content

made_core/entities/
council_journal_event.rs

1use serde::{Deserialize, Serialize};
2
3use crate::entities::{Council, CouncilSnapshotProvenance, Deliberation, Statistics};
4use crate::events::{
5    DeliberationCompletedEvent, PhaseChangedEvent, TaskCompletedEvent, TaskDispatchedEvent,
6    TaskFailedEvent,
7};
8use crate::ports::AgentDescriptor;
9use crate::value_objects::{AgentId, EventId, OutputContract, OutputContractId, Specialty};
10
11/// Council facts have their own durable order, separate from ceremony events.
12/// A saved deliberation is explicitly a snapshot, never an invented phase history.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14#[serde(tag = "kind", content = "fact", rename_all = "snake_case")]
15pub enum CouncilJournalEvent {
16    SnapshotImported(CouncilSnapshotProvenance),
17    CouncilRegistered(Council),
18    CouncilReplaced(Council),
19    CouncilDeleted(Specialty),
20    AgentRegistered(AgentDescriptor),
21    AgentUnregistered(AgentId),
22    ContractRegistered(OutputContract),
23    ContractDeleted(OutputContractId),
24    DeliberationSnapshotSaved(Deliberation),
25    StatisticsRecorded(Statistics),
26    TaskDispatched(TaskDispatchedEvent),
27    TaskCompleted(TaskCompletedEvent),
28    TaskFailed(TaskFailedEvent),
29    DeliberationCompleted(DeliberationCompletedEvent),
30    PhaseChanged(PhaseChangedEvent),
31}
32
33impl CouncilJournalEvent {
34    /// The caller's stable publication identity, if this is a messaging fact.
35    #[must_use]
36    pub fn publication_id(&self) -> Option<&EventId> {
37        match self {
38            Self::TaskDispatched(event) => Some(event.envelope().event_id()),
39            Self::TaskCompleted(event) => Some(event.envelope().event_id()),
40            Self::TaskFailed(event) => Some(event.envelope().event_id()),
41            Self::DeliberationCompleted(event) => Some(event.envelope().event_id()),
42            Self::PhaseChanged(event) => Some(event.envelope().event_id()),
43            _ => None,
44        }
45    }
46}