getNextStep method

Enum? getNextStep(
  1. S step
)

Implementation

Enum? getNextStep(S step) {
  __.in_('getNextStep');
  try {
    checkInitialized('BaseFlow');

    // Check if this is the last step in the flow
    if (step == getLastStep()) {
      __.info('Last step reached, returning BaseFlowStep.end');
      return BaseFlowStep.end as Enum;
    }

    // Get transitions map from the concrete flow
    final transitions = getTransitionsForFlow();

    // If no transitions map, return null (no next step)
    if (transitions == null) {
      return null;
    }

    // Check if there's a next step function for this step
    if (transitions.containsKey(step)) {
      final transition = transitions[step];
      if (transition?.nextStep != null) {
        // Call the next step function with the current flow state
        final nextStep = transition!.nextStep(flowState);
        __.info(
          'Next step after ${step.name}: ${nextStep?.toString() ?? "none"}',
        );
        return nextStep;
      }
    }

    // No next step defined for this step
    return null;
  } catch (e, stackTrace) {
    __.severe('Error getting next step', e, stackTrace);
    return null;
  } finally {
    __.out_('getNextStep');
  }
}