made_core/entities/ceremony_instance/
participant_bindings.rs1use super::{
2 BTreeMap, CeremonyDefinition, CeremonyInstance, CeremonyParticipantBinding, DomainError,
3 OffsetDateTime, RoleId, Specialty,
4};
5
6impl CeremonyInstance {
7 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 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 #[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}