Skip to main content

made_core/entities/ceremony_instance/decisions/
mod.rs

1//! Deciding: what a command would do to this session, as events.
2//!
3//! Every invariant, lease, idempotency, authorization and
4//! terminal-state rule the aggregate holds is checked here, against
5//! the definition and the current state, and nothing is written. A
6//! refused command returns the same error the mutator it replaces
7//! returned; an accepted one returns the events whose fold is exactly
8//! that mutator's effect. One file per command family.
9
10use crate::entities::{CeremonyCommand, CeremonyDefinition, CeremonyEvent, CeremonyInstance};
11use crate::error::DomainError;
12
13mod guard_decisions;
14mod interventions;
15mod participant_bindings;
16mod reasons;
17mod start;
18mod step_execution;
19mod transitions;
20
21impl CeremonyInstance {
22    /// Decide a command against this session and its definition.
23    ///
24    /// Pure: reads the session, writes nothing, and returns the events
25    /// that would change it — usually one; two where one act has two
26    /// facts to record, as a transition into a terminal state also
27    /// completes the ceremony. Fold them with [`Self::apply`] to get
28    /// the state the corresponding mutator would have left.
29    pub fn decide(
30        &self,
31        command: &CeremonyCommand,
32        definition: &CeremonyDefinition,
33    ) -> Result<Vec<CeremonyEvent>, DomainError> {
34        match command {
35            CeremonyCommand::BindParticipant(command) => {
36                self.decide_bind_participant(command, definition)
37            }
38            CeremonyCommand::StartStep(command) => self.decide_start_step(command, definition),
39            CeremonyCommand::ApplyStepResult(command) => {
40                self.decide_apply_step_result(command, definition)
41            }
42            CeremonyCommand::ApplyTransition(command) => {
43                self.decide_apply_transition(command, definition)
44            }
45            CeremonyCommand::ApproveGuard(command) => {
46                self.decide_approve_guard(command, definition)
47            }
48            CeremonyCommand::DeferGuard(command) => self.decide_defer_guard(command, definition),
49            CeremonyCommand::RequestIntervention(command) => {
50                self.decide_request_intervention(command, definition)
51            }
52            CeremonyCommand::RespondToIntervention(command) => {
53                self.decide_respond_to_intervention(command, definition)
54            }
55            CeremonyCommand::RespondToInterventionWithEvidence(command) => {
56                self.decide_respond_to_intervention_with_evidence(command, definition)
57            }
58            CeremonyCommand::AssertReason(command) => {
59                self.decide_assert_reason(command, definition)
60            }
61            CeremonyCommand::CloseIntervention(command) => {
62                self.decide_close_intervention(command, definition)
63            }
64        }
65    }
66}