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 budget_admission;
14mod children;
15mod execution_receipts;
16mod guard_decisions;
17mod interventions;
18mod lifecycle;
19mod participant_bindings;
20mod reasons;
21mod start;
22mod step_execution;
23mod transitions;
24
25impl CeremonyInstance {
26    /// Decide a command against this session and its definition.
27    ///
28    /// Pure: reads the session, writes nothing, and returns the events
29    /// that would change it — usually one; two where one act has two
30    /// facts to record, as a transition into a terminal state also
31    /// completes the ceremony. Fold them with [`Self::apply`] to get
32    /// the state the corresponding mutator would have left.
33    pub fn decide(
34        &self,
35        command: &CeremonyCommand,
36        definition: &CeremonyDefinition,
37    ) -> Result<Vec<CeremonyEvent>, DomainError> {
38        match command {
39            CeremonyCommand::BindParticipant(command) => {
40                self.decide_bind_participant(command, definition)
41            }
42            CeremonyCommand::StartStep(command) => self.decide_start_step(command, definition),
43            CeremonyCommand::ApplyStepResult(command) => {
44                self.decide_apply_step_result(command, definition)
45            }
46            CeremonyCommand::ApplyExecutionReceiptResult(command) => {
47                self.decide_apply_execution_receipt_result(command, definition)
48            }
49            CeremonyCommand::ApplyTransition(command) => {
50                self.decide_apply_transition(command, definition)
51            }
52            CeremonyCommand::ApproveGuard(command) => {
53                self.decide_approve_guard(command, definition)
54            }
55            CeremonyCommand::DeferGuard(command) => self.decide_defer_guard(command, definition),
56            CeremonyCommand::RequestIntervention(command) => {
57                self.decide_request_intervention(command, definition)
58            }
59            CeremonyCommand::RespondToIntervention(command) => {
60                self.decide_respond_to_intervention(command, definition)
61            }
62            CeremonyCommand::RespondToInterventionWithEvidence(command) => {
63                self.decide_respond_to_intervention_with_evidence(command, definition)
64            }
65            CeremonyCommand::AssertReason(command) => {
66                self.decide_assert_reason(command, definition)
67            }
68            CeremonyCommand::CloseIntervention(command) => {
69                self.decide_close_intervention(command, definition)
70            }
71            CeremonyCommand::PlanCeremonyChildren(command) => {
72                self.decide_plan_children(command, definition)
73            }
74            CeremonyCommand::AdoptChildSpawnPlan(command) => {
75                self.decide_adopt_child_plan(command, definition)
76            }
77            CeremonyCommand::AcceptChildCompletion(command) => {
78                self.decide_accept_child_completion(command, definition)
79            }
80            CeremonyCommand::PauseCeremony(command) => self.decide_pause(command, definition),
81            CeremonyCommand::ResumeCeremony(command) => self.decide_resume(command, definition),
82            CeremonyCommand::CancelCeremony(command) => self.decide_cancel(command, definition),
83            CeremonyCommand::EnforceCeremonyDeadlines(command) => {
84                self.decide_enforce_deadlines(command, definition)
85            }
86        }
87    }
88}