subject_type() ) { SubjectType::Booking => $this->refresh_booking( $ctx ), SubjectType::Customer => $this->refresh_customer( $ctx ), SubjectType::Intent => $this->refresh_intent( $ctx ), SubjectType::Payment => $ctx, }; } /** * Refresh a booking. * * @param AutomationContext $ctx Snapshot. */ private function refresh_booking( AutomationContext $ctx ): ?AutomationContext { $booking = $this->bookings->find_by_id( $ctx->subject_id() ); if ( null === $booking || $this->factory->booking_is_void( $booking ) ) { return null; } $customer = $this->customers->find_by_id( $booking->customer_id() ); $fresh = $this->factory->for_booking( $ctx->event(), $ctx->trigger_event_id(), $booking, $customer, $ctx->is_test() ); return $ctx->with_fields( $fresh->fields(), $fresh->snapshot_at() ); } /** * Refresh a customer. * * @param AutomationContext $ctx Snapshot. */ private function refresh_customer( AutomationContext $ctx ): ?AutomationContext { $customer = $this->customers->find_by_id( $ctx->subject_id() ); if ( null === $customer ) { return null; } $fresh = $this->factory->for_customer( $ctx->event(), $ctx->trigger_event_id(), $customer, $ctx->is_test() ); return $ctx->with_fields( $fresh->fields(), $fresh->snapshot_at() ); } /** * Refresh an intent. * * @param AutomationContext $ctx Snapshot. */ private function refresh_intent( AutomationContext $ctx ): ?AutomationContext { $intent = $this->intents->find_by_id( $ctx->subject_id() ); if ( null === $intent ) { return null; } $fresh = $this->factory->for_intent( $ctx->event(), $ctx->trigger_event_id(), $intent, $ctx->is_test() ); return $ctx->with_fields( $fresh->fields(), $fresh->snapshot_at() ); } }