/// Basic batch order processing demonstrating the foreach parallel fan-out pattern.
///
/// Fetches all pending orders for a customer and concurrently validates then processes each
/// one. This is a simplified variant of the batch-order-parallel graph, showing the essential
/// foreach structure without additional aggregation or stock deduction steps.
///
/// Key DSL concepts demonstrated:
///   foreach (parallel)  — default mode; each (order, idx) pair is processed concurrently
///   depends_on          — process waits for validate to succeed within the same iteration
///
/// Context variables:
///   ctx.customerId — identifies the customer whose pending orders are fetched
graph batchOrderProcessing {
  /// Retrieves all pending orders for the customer
  node fetchOrders : OrderFetcher {
    input {
      customerId = ctx.customerId
    }
  }

  /// foreach parallel mode (default): each order is processed concurrently
  /// order — variable referencing the current order item
  /// idx   — variable referencing the 0-based position in the orders list
  foreach processOrders : (order, idx) in fetchOrders.output.orders {
    /// Validates the order structure and business rules
    node validate : OrderValidator {
      input {
        order = order
        index = idx
      }
    }
    /// Processes the validated order (e.g. persists, triggers fulfilment)
    node process : OrderProcessor {
      depends_on = [validate]
      input {
        validated = validate.output
      }
    }
  }
}
