{
  "name": "SLA Monitoring Workflow",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Every 15 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.BACKEND_URL }}/api/v1/webhooks/sla-check",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "check-sla",
      "name": "Check SLA Breaches",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        450,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.data.breached_count }}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      },
      "id": "has-breaches",
      "name": "Has Breaches?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data.breached_complaints",
        "options": {}
      },
      "id": "split-breaches",
      "name": "Split Into Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        850,
        250
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.escalation_level }}",
              "operation": "equals",
              "value2": "none"
            }
          ]
        }
      },
      "id": "check-escalated",
      "name": "Already Escalated?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1050,
        250
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.BACKEND_URL }}/api/v1/webhooks/escalate",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "complaint_id",
              "value": "={{ $json.id }}"
            },
            {
              "name": "escalation_level",
              "value": "level_1"
            },
            {
              "name": "reason",
              "value": "SLA deadline exceeded"
            }
          ]
        },
        "options": {}
      },
      "id": "create-escalation",
      "name": "Create Escalation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1250,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.BACKEND_URL }}/api/v1/webhooks/notify",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "type",
              "value": "sla_breach"
            },
            {
              "name": "complaint_id",
              "value": "={{ $json.id }}"
            },
            {
              "name": "recipients",
              "value": "={{ JSON.stringify(['department_head', 'admin']) }}"
            },
            {
              "name": "message",
              "value": "SLA breached for complaint #{{ $json.id.slice(0, 8) }} - Immediate attention required"
            }
          ]
        },
        "options": {}
      },
      "id": "notify-breach",
      "name": "Notify SLA Breach",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1450,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.BACKEND_URL }}/api/v1/webhooks/escalate-upgrade",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "complaint_id",
              "value": "={{ $json.id }}"
            },
            {
              "name": "current_level",
              "value": "={{ $json.escalation_level }}"
            }
          ]
        },
        "options": {}
      },
      "id": "upgrade-escalation",
      "name": "Check Escalation Upgrade",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1250,
        350
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "status",
              "value": "completed"
            },
            {
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}"
            }
          ],
          "number": [
            {
              "name": "processed_count",
              "value": "={{ $json.data.breached_count || 0 }}"
            }
          ]
        },
        "options": {}
      },
      "id": "log-result",
      "name": "Log Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        850,
        400
      ]
    },
    {
      "parameters": {},
      "id": "no-op",
      "name": "No Breaches",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    }
  ],
  "connections": {
    "Every 15 Minutes": {
      "main": [
        [
          {
            "node": "Check SLA Breaches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check SLA Breaches": {
      "main": [
        [
          {
            "node": "Has Breaches?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Breaches?": {
      "main": [
        [
          {
            "node": "Split Into Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Breaches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Into Items": {
      "main": [
        [
          {
            "node": "Already Escalated?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Already Escalated?": {
      "main": [
        [
          {
            "node": "Create Escalation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Escalation Upgrade",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Escalation": {
      "main": [
        [
          {
            "node": "Notify SLA Breach",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify SLA Breach": {
      "main": [
        [
          {
            "node": "Split Into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Escalation Upgrade": {
      "main": [
        [
          {
            "node": "Split Into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "staticData": null,
  "tags": [
    {
      "name": "complaint-management"
    },
    {
      "name": "sla-monitoring"
    },
    {
      "name": "production"
    }
  ],
  "triggerCount": 1,
  "active": true
}