{
  "name": "Rejected Workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "rejected",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "orderId",
              "value": "={{ $json.body.orderId }}"
            },
            {
              "name": "rejectionReason",
              "value": "={{ $json.body.orderData.validation.issues[0].message }}"
            },
            {
              "name": "customerEmail",
              "value": "={{ $json.body.orderData.customerEmail }}"
            }
          ]
        },
        "options": {}
      },
      "id": "set-variables",
      "name": "Set Variables",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "email.verify.921@gmail.com",
        "subject": "=Order Cannot Be Processed - Order {{ $json.body.orderId }}",
        "message": "=We're sorry, but your order cannot be processed at this time.\n\nOrder ID: {{ $json.body.orderId }}\n\nReason: {{ $json.body.orderData.validation.issues[0].message }}\n\nPlease contact us to discuss alternatives or corrections.",
        "toEmail": "={{ $json.body.orderData.customerEmail }}",
        "options": {}
      },
      "id": "send-rejection-email",
      "name": "Send Rejection Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://backend:3000/api/v1/orders/{{ $json.orderId }}",
        "method": "GET",
        "options": {}
      },
      "id": "log-to-database",
      "name": "Log to Database",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "email.verify.921@gmail.com",
        "subject": "=Order Rejected - Internal Notification - {{ $json.body.orderId }}",
        "message": "=Order {{ $json.body.orderId }} has been rejected.\n\nReason: {{ $json.body.orderData.validation.issues[0].message }}\nCustomer: {{ $json.body.orderData.customerName }}\nEmail: {{ $json.body.orderData.customerEmail }}\n\nNo further action required.",
        "toEmail": "admin@printcompany.com",
        "options": {}
      },
      "id": "notify-admin",
      "name": "Notify Admin",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Order rejected, customer notified', resumeUrl: $execution.resumeUrl, orderId: $json.body.orderId }) }}"
      },
      "id": "webhook-response",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        450,
        450
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Set Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Variables": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Response": {
      "main": [
        [
          {
            "node": "Send Rejection Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Rejection Email": {
      "main": [
        [
          {
            "node": "Log to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Database": {
      "main": [
        [
          {
            "node": "Notify Admin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "versionId": "1",
  "id": "3",
  "tags": []
}