Skip to main content

made_core/entities/ceremony_instance/fold/
start.rs

1use std::collections::{BTreeMap, BTreeSet};
2
3use crate::entities::ceremony_events::CeremonyInstanceStarted;
4use crate::entities::CeremonyInstance;
5use crate::value_objects::StepExecutionRecord;
6use crate::value_objects::{StateIteration, StateVisit};
7
8impl CeremonyInstance {
9    /// Open the session the event describes: its initial state, one
10    /// pending record per step the definition declared, and nothing
11    /// else yet. Needs no definition, because the event carries what
12    /// starting derived from one.
13    #[must_use]
14    pub fn from_started(started: &CeremonyInstanceStarted) -> Self {
15        Self {
16            lease_renewals: BTreeMap::new(),
17            host_handoffs: BTreeMap::new(),
18            id: started.ceremony_id.clone(),
19            definition_name: started.definition_name.clone(),
20            definition_version: started.definition_version.clone(),
21            current_state: started.initial_state.clone(),
22            current_state_iteration: StateIteration::FIRST,
23            current_state_visit: StateVisit::FIRST,
24            step_records: started
25                .step_ids
26                .iter()
27                .map(|step_id| (step_id.clone(), StepExecutionRecord::pending()))
28                .collect(),
29            step_record_history: BTreeMap::new(),
30            interventions: Vec::new(),
31            guard_deferrals: Vec::new(),
32            guard_approvals: Vec::new(),
33            transitions: Vec::new(),
34            reasons: Vec::new(),
35            participant_bindings: BTreeMap::new(),
36            context: started.context.clone(),
37            recollection: None,
38            idempotency_keys: BTreeSet::new(),
39            created_at: started.created_at,
40            updated_at: started.created_at,
41            completed_at: None,
42            bound_definition: started.bound_definition,
43            lineage: started.lineage.clone(),
44            budget_account_id: started.budget_account_id.clone(),
45            child_groups: BTreeMap::new(),
46            lifecycle: crate::value_objects::CeremonyLifecycle::default(),
47            ceremony_deadline: started.ceremony_deadline,
48            state_deadline: started.state_deadline.clone(),
49            step_deadlines: BTreeMap::new(),
50            retired_deadline_claims: BTreeMap::new(),
51            late_step_results: BTreeMap::new(),
52            execution_receipt_links: BTreeMap::new(),
53            execution_receipt_adoptions: BTreeMap::new(),
54            succession: started.succession.clone(),
55            successor_plan: None,
56        }
57    }
58}