Skip to main content

made_core/entities/ceremony_instance/
participant_bindings.rs

1use super::{
2    BTreeMap, CeremonyDefinition, CeremonyInstance, CeremonyParticipantBinding, DomainError,
3    OffsetDateTime, RoleId, Specialty,
4};
5
6impl CeremonyInstance {
7    /// Seat a role for this session.
8    ///
9    /// Rebinding is allowed and deliberate: a panel can become
10    /// unavailable halfway through a working session, and a ceremony
11    /// that could not be re-seated would have to be abandoned and
12    /// started again, losing everything already decided. What was
13    /// seated before stays in the journal; the instance carries who is
14    /// seated now, which is what the next step needs.
15    pub fn bind_participant(
16        &mut self,
17        definition: &CeremonyDefinition,
18        role_id: RoleId,
19        specialty: Specialty,
20        now: OffsetDateTime,
21    ) -> Result<(), DomainError> {
22        self.require_active(
23            definition,
24            "terminal ceremony instances cannot be re-seated",
25        )?;
26        // A seat that the ceremony never declared is not a seat.
27        if definition.role(&role_id).is_none() {
28            return Err(DomainError::NotFound {
29                what: "ceremony_role",
30            });
31        }
32        self.participant_bindings.insert(
33            role_id.clone(),
34            CeremonyParticipantBinding::record(role_id, specialty, now),
35        );
36        self.updated_at = now;
37        Ok(())
38    }
39
40    #[must_use]
41    pub fn participant_bindings(&self) -> &BTreeMap<RoleId, CeremonyParticipantBinding> {
42        &self.participant_bindings
43    }
44
45    /// The specialty a role's work should be put to, if this session
46    /// seated one. `None` means the definition decides, as usual.
47    #[must_use]
48    pub fn bound_specialty(&self, role_id: &RoleId) -> Option<&Specialty> {
49        self.participant_bindings
50            .get(role_id)
51            .map(CeremonyParticipantBinding::specialty)
52    }
53}