{
  "name": "Vorlux AI | Subscription Monitor",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "hours", "hoursInterval": 6 }] } }, "id": "sched", "name": "Every 6 Hours", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/finance/subscriptions", "method": "GET", "options": { "timeout": 15000 } }, "id": "fetch-subs", "name": "Fetch Subscriptions", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const subs = $input.first().json.data || $input.first().json.subscriptions || [];\nconst now = Date.now();\nconst atRisk = subs.filter(s => s.cancel_at_period_end || s.status === 'past_due');\nconst expiring = subs.filter(s => s.current_period_end && new Date(s.current_period_end).getTime() - now < 7 * 86400000);\nreturn [{ json: { total: subs.length, active: subs.filter(s => s.status === 'active').length, atRisk: atRisk.length, expiringSoon: expiring.length, alerts: atRisk.concat(expiring).slice(0, 10) } }];" }, "id": "analyze", "name": "Analyze Subscriptions", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [700, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/admin/revenue/alerts", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ type: 'subscription-monitor', alerts: $json.alerts }) }}", "options": { "timeout": 10000 } }, "id": "save-alerts", "name": "Save Alerts", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 200] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_OPS_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '🔔 **Subscription Monitor**\\nTotal: ' + $json.total + ' | Active: ' + $json.active + '\\nAt Risk: ' + $json.atRisk + ' | Expiring Soon: ' + $json.expiringSoon }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 400] }
  ],
  "connections": {
    "Every 6 Hours": { "main": [[{ "node": "Fetch Subscriptions", "type": "main", "index": 0 }]] },
    "Fetch Subscriptions": { "main": [[{ "node": "Analyze Subscriptions", "type": "main", "index": 0 }]] },
    "Analyze Subscriptions": { "main": [[{ "node": "Save Alerts", "type": "main", "index": 0 }, { "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
