{
  "name": "Error Handling & Recovery Demo",
  "version": "1.0.0",
  "description": "Demonstrates error handling with trycatch control flow - API call with fallback",
  "input_schema": {
    "type": "object",
    "properties": {
      "api_url": {
        "type": "string",
        "description": "API URL to call",
        "default": "https://jsonplaceholder.typicode.com/posts/1"
      },
      "fallback_data": {
        "type": "object",
        "description": "Fallback data if API fails",
        "default": {
          "id": 0,
          "title": "Fallback Title",
          "body": "This is fallback content used when the API is unavailable."
        }
      }
    },
    "required": []
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "success": { "type": "boolean" },
      "data": { "type": "object" },
      "source": { "type": "string" }
    }
  },
  "stages": [
    {
      "id": "log-start",
      "name": "Log Request Start",
      "component_type": "logger",
      "config": {
        "message": "Starting API fetch with trycatch error handling",
        "level": "info",
        "data": {
          "url": "{{input.api_url}}"
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 200 }
    },
    {
      "id": "try-api-call",
      "name": "Try API Call",
      "component_type": "trycatch",
      "config": {
        "try_stages": ["fetch-api"],
        "catch_stages": ["use-fallback"],
        "finally_stages": [],
        "error_scope": "continue"
      },
      "depends_on": ["log-start"],
      "position": { "x": 300, "y": 200 }
    },
    {
      "id": "fetch-api",
      "name": "Fetch API Data",
      "component_type": "http_request",
      "config": {
        "url": "{{input.api_url}}",
        "method": "GET",
        "timeout": 10,
        "verify_ssl": true
      },
      "depends_on": ["try-api-call"],
      "position": { "x": 500, "y": 100 }
    },
    {
      "id": "use-fallback",
      "name": "Use Fallback Data",
      "component_type": "json_transform",
      "config": {
        "data": "{{input.fallback_data}}",
        "jmespath_expression": "@"
      },
      "depends_on": ["try-api-call"],
      "position": { "x": 500, "y": 300 }
    },
    {
      "id": "process-result",
      "name": "Process Result",
      "component_type": "json_transform",
      "config": {
        "data": {
          "api_result": "{{upstream.fetch-api}}",
          "trycatch_status": "{{upstream.try-api-call}}"
        },
        "jmespath_expression": "{ success: trycatch_status.status == 'success', data: api_result.body || api_result, source: trycatch_status.status == 'success' && 'api' || 'fallback' }"
      },
      "depends_on": ["try-api-call"],
      "position": { "x": 700, "y": 200 }
    },
    {
      "id": "log-result",
      "name": "Log Result",
      "component_type": "logger",
      "config": {
        "message": "API fetch completed with trycatch handling",
        "level": "info",
        "data": {
          "source": "{{upstream.process-result.result.source}}"
        }
      },
      "depends_on": ["process-result"],
      "position": { "x": 900, "y": 200 }
    },
    {
      "id": "format-output",
      "name": "Format Final Output",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.process-result.result}}",
        "jmespath_expression": "{ success: success, data: data, source: source }"
      },
      "depends_on": ["log-result"],
      "position": { "x": 1100, "y": 200 }
    }
  ],
  "output_stage_id": "format-output"
}
