{
  "name": "Batch Processing Pipeline",
  "version": "1.0.0",
  "description": "Demonstrates foreach control flow for iterating over items with transformation",
  "input_schema": {
    "type": "object",
    "properties": {
      "items": {
        "type": "array",
        "description": "Items to process in batches",
        "items": {
          "type": "object",
          "properties": {
            "id": { "type": "string" },
            "name": { "type": "string" },
            "value": { "type": "number" }
          }
        },
        "default": [
          { "id": "1", "name": "Item A", "value": 100 },
          { "id": "2", "name": "Item B", "value": 250 },
          { "id": "3", "name": "Item C", "value": 75 },
          { "id": "4", "name": "Item D", "value": 300 },
          { "id": "5", "name": "Item E", "value": 150 }
        ]
      },
      "threshold": {
        "type": "number",
        "description": "Value threshold for high-value classification",
        "default": 100
      }
    },
    "required": []
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "processed_items": { "type": "array" },
      "summary": { "type": "object" }
    }
  },
  "stages": [
    {
      "id": "log-start",
      "name": "Log Batch Start",
      "component_type": "logger",
      "config": {
        "message": "Starting foreach batch processing",
        "level": "info",
        "data": {
          "item_count": "{{input.items}}"
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 200 }
    },
    {
      "id": "process-each-item",
      "name": "Process Each Item",
      "component_type": "foreach",
      "config": {
        "items": "{{input.items}}",
        "loop_stages": ["transform-item"],
        "item_variable": "current_item",
        "index_variable": "item_index",
        "collect_results": true,
        "parallel": false
      },
      "depends_on": ["log-start"],
      "position": { "x": 300, "y": 200 }
    },
    {
      "id": "transform-item",
      "name": "Transform Item",
      "component_type": "json_transform",
      "config": {
        "data": {
          "item": "{{context.current_item}}",
          "index": "{{context.item_index}}",
          "threshold": "{{input.threshold}}"
        },
        "jmespath_expression": "{ id: item.id, name: item.name, value: item.value, index: index, is_high_value: item.value >= threshold, processed: `true` }"
      },
      "depends_on": ["process-each-item"],
      "position": { "x": 500, "y": 200 }
    },
    {
      "id": "filter-high-value",
      "name": "Filter High Value Items",
      "component_type": "filter",
      "config": {
        "data": "{{upstream.process-each-item.results}}",
        "condition": "item.get('result', {}).get('is_high_value', False)",
        "filter_mode": "filter_array"
      },
      "depends_on": ["process-each-item"],
      "position": { "x": 700, "y": 100 }
    },
    {
      "id": "calculate-summary",
      "name": "Calculate Summary",
      "component_type": "json_transform",
      "config": {
        "data": {
          "all_items": "{{upstream.process-each-item.results}}",
          "high_value_items": "{{upstream.filter-high-value.data}}",
          "foreach_info": "{{upstream.process-each-item}}"
        },
        "jmespath_expression": "{ total_items: foreach_info.total_iterations, high_value_count: length(high_value_items), total_value: sum(all_items[*].value), high_value_total: sum(high_value_items[*].value) }"
      },
      "depends_on": ["filter-high-value"],
      "position": { "x": 700, "y": 300 }
    },
    {
      "id": "log-complete",
      "name": "Log Processing Complete",
      "component_type": "logger",
      "config": {
        "message": "Foreach batch processing complete",
        "level": "info",
        "data": {
          "total_processed": "{{upstream.calculate-summary.result.total_items}}",
          "high_value_count": "{{upstream.calculate-summary.result.high_value_count}}"
        }
      },
      "depends_on": ["calculate-summary"],
      "position": { "x": 900, "y": 200 }
    },
    {
      "id": "format-output",
      "name": "Format Final Output",
      "component_type": "json_transform",
      "config": {
        "data": {
          "processed": "{{upstream.process-each-item.results}}",
          "high_value": "{{upstream.filter-high-value.data}}",
          "summary": "{{upstream.calculate-summary.result}}"
        },
        "jmespath_expression": "{ processed_items: processed, high_value_items: high_value, summary: summary }"
      },
      "depends_on": ["log-complete"],
      "position": { "x": 1100, "y": 200 }
    }
  ],
  "output_stage_id": "format-output"
}
