{
  "name": "Wranngle Lead Intake (Centralized)",
  "nodes": [
    {
      "id": "webhook-trigger",
      "name": "Lead Intake Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ],
      "parameters": {
        "path": "wranngle-intake-form",
        "httpMethod": "POST",
        "responseMode": "onReceived",
        "responseData": "{ \"success\": true, \"message\": \"Lead received for processing\" }",
        "authentication": "headerAuth",
        "options": {}
      }
    },
    {
      "id": "call-enrichment",
      "name": "Enrich Lead Data",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        470,
        300
      ],
      "parameters": {
        "workflowId": "lead-enrichment-microservice",
        "mode": "id"
      }
    },
    {
      "id": "save-db",
      "name": "Save Enriched Lead to DB",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.3,
      "position": [
        690,
        100
      ],
      "parameters": {
        "operation": "insert",
        "schema": "public",
        "table": "leads",
        "columns": "business_name, industry, owner_name, email, phone, enrichment_data, ai_research, timestamp",
        "values": "={{ $json.businessName }}, {{ $json.industry }}, {{ $json.ownerName }}, {{ $json.email }}, {{ $json.phone }}, {{ JSON.stringify($json) }}, {{ $json.ai_research }}, {{ new Date().toISOString() }}"
      }
    },
    {
      "id": "email-notification",
      "name": "Send Enriched Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        690,
        300
      ],
      "parameters": {
        "fromEmail": "noreply@wranngle.com",
        "toEmail": "sales@wranngle.com",
        "subject": "=\ud83d\udd14 Enriched Lead: {{ $json.businessName }} ({{ $json.company_name || 'New' }})",
        "emailType": "html",
        "message": "=<h2>New Enriched Lead Submission</h2><p><strong>Business:</strong> {{ $json.businessName }}</p><p><strong>Enriched Name:</strong> {{ $json.company_name }}</p><p><strong>Industry:</strong> {{ $json.industry }}</p><p><strong>Owner:</strong> {{ $json.ownerName }}</p><p><strong>Email:</strong> {{ $json.email }}</p><p><strong>Phone:</strong> {{ $json.phone }}</p><h3>AI Research</h3><p>{{ $json.ai_research }}</p>"
      }
    },
    {
      "id": "universal-messenger",
      "name": "Trigger Universal Messenger",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        690,
        500
      ],
      "parameters": {
        "method": "POST",
        "url": "https://n8n.wranngle.com/webhook/universal-message-sender",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "template",
              "value": "lead-intake"
            },
            {
              "name": "variables",
              "value": "={ \"BUSINESS_NAME\": \"{{ $json.businessName }}\", \"ENRICHED_INFO\": \"{{ $json.ai_research }}\" }"
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Lead Intake Webhook": {
      "main": [
        [
          {
            "node": "Enrich Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Lead Data": {
      "main": [
        [
          {
            "node": "Save Enriched Lead to DB",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Enriched Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Trigger Universal Messenger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}