intent() ?? SendIntent::Transactional; if ( SendIntent::Marketing === $intent && ! $ctx->field_bool( 'marketing_consent' ) ) { return ActionResult::skipped( SkipReason::NoMarketingConsent ); } $recipient = $step->recipient() ?? AutomationRecipient::Customer; if ( AutomationRecipient::Agent === $recipient && $ctx->field_int( 'agent_id' ) <= 0 ) { return ActionResult::skipped( SkipReason::NoRecipient ); } $entry = $this->dispatcher->queue_for_automation( $ctx, $step ); if ( ! $entry instanceof NotificationLogEntry ) { return ActionResult::failed( 'Could not queue notification — template missing or recipient unavailable.' ); } $template = $step->config()['template_key'] ?? ''; $rendered = sprintf( '%s → %s (%s)', is_string( $template ) ? $template : '', $recipient->value, $intent->value ); $extra = [ 'notification_log_id' => (int) $entry->id(), 'notification_subject' => $entry->subject(), ]; if ( NotificationStatus::Drafted === $entry->status() || ! OutboundGuard::allows_outbound() ) { return ActionResult::drafted( $rendered, $extra ); } return ActionResult::completed( $rendered, 1, $extra ); } }