getResolvedInputControls method

Future<Map<String, dynamic>> getResolvedInputControls(
  1. RuleNode node,
  2. Map<String, RuleNode> nodes,
  3. Map<String, dynamic> context
)

Implementation

Future<Map<String, dynamic>> getResolvedInputControls(
  RuleNode node,
  Map<String, RuleNode> nodes,
  Map<String, dynamic> context,
) async {
  final inputData = _castToStringMap(node.data['inputData']) ?? {};
  final resolvedInputs = <String, dynamic>{};

  // Get input connections from the node
  final connections = _castToStringMap(node.data['connections']) ?? {};
  final inputs = _castToStringMap(connections['inputs']) ?? {};

  // Process connected inputs first
  for (final entry in inputs.entries) {
    final portName = entry.key;
    final connectionsList = entry.value as List<dynamic>? ?? [];

    if (connectionsList.isNotEmpty) {
      // Take the first connection for this port
      final connection = connectionsList.first as Map<String, dynamic>;
      final sourceNodeId = connection['nodeId'] as String;
      final sourcePortName = connection['portName'] as String;

      // Execute the source node to get its output
      try {
        final sourceResult = await callNode(
          nodeId: sourceNodeId,
          nodes: nodes,
          context: context,
        );

        // Extract the specific port value
        if (sourceResult.containsKey(sourcePortName)) {
          resolvedInputs[portName] = sourceResult[sourcePortName];
        } else {
          resolvedInputs[portName] = sourceResult;
        }
      } catch (e) {
        resolvedInputs[portName] = null;
      }
    }
  }

  // Process static input data for ports not connected
  for (final entry in inputData.entries) {
    final portName = entry.key;

    // Only use static data if no connection exists
    if (!resolvedInputs.containsKey(portName)) {
      resolvedInputs[portName] = resolveInputControls(entry.value, context);
    }
  }

  return resolvedInputs;
}