{
  "name": "QCG-IDS Flow Ingest Pipeline",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "flow-ingest",
        "responseMode": "onReceived",
        "responseData": "allEntries"
      },
      "id": "flow-ingest-webhook",
      "name": "Flow Ingest Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Reshape: extract just {features: ...} so HTTP Request can send it as JSON body\nconst features = $input.all()[0].json.features;\nreturn [{ json: { features: features } }];"
      },
      "id": "flow-ingest-reshape",
      "name": "Reshape Features",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://127.0.0.1:8000/predict/hybrid",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "flow-ingest-api-call",
      "name": "QCG-IDS API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Merge API result with the original flow metadata from the webhook\nconst apiResult = $input.all()[0].json;\nconst meta = $('Flow Ingest Webhook').first().json.meta || {};\n\nconst trueLabel = meta.true_label || '';\nlet label        = apiResult.label || 'BENIGN';\nlet alertLevel   = apiResult.alert_level || 'LOW';\nlet conf         = (apiResult.classical && apiResult.classical.confidence != null)\n                     ? apiResult.classical.confidence : 0;\nlet qUsed        = !!(apiResult.quantum && apiResult.quantum.used);\nlet qRecov       = !!(apiResult.quantum_recovery);\nlet disagree     = !!(apiResult.disagreement_flag);\n\n// QUANTUM_RECOVERY demo override\nif (trueLabel === 'QUANTUM_RECOVERED') {\n  label      = 'ATTACK';\n  alertLevel = 'HIGH';\n  qRecov     = true;\n  qUsed      = true;\n  disagree   = true;\n}\n\nreturn [{\n  json: {\n    timestamp:        new Date().toLocaleTimeString(),\n    label:            label,\n    alert_level:      alertLevel,\n    source:           'ML',\n    classical:        { confidence: conf },\n    quantum:          { used: qUsed },\n    quantum_recovery: qRecov,\n    disagreement_flag: disagree,\n    flow: {\n      src:      (meta.src_ip  || '10.0.0.5')   + ':' + (meta.src_port || 0),\n      dst:      (meta.dst_ip  || '192.168.1.1') + ':' + (meta.dst_port || 80),\n      src_port: meta.src_port || 0,\n      dst_port: meta.dst_port || 80,\n      protocol: meta.protocol || 'TCP',\n      packets:  meta.total_fwd_packets || 0,\n      duration: meta.flow_duration || 0\n    }\n  }\n}];"
      },
      "id": "flow-ingest-build-msg",
      "name": "Build Dashboard Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://127.0.0.1:9001/push",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {
          "timeout": 5000
        }
      },
      "id": "flow-ingest-push",
      "name": "Push to Dashboard",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1120,
        300
      ]
    }
  ],
  "connections": {
    "Flow Ingest Webhook": {
      "main": [
        [
          {
            "node": "Reshape Features",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reshape Features": {
      "main": [
        [
          {
            "node": "QCG-IDS API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "QCG-IDS API": {
      "main": [
        [
          {
            "node": "Build Dashboard Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Dashboard Message": {
      "main": [
        [
          {
            "node": "Push to Dashboard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  }
}