{
  "name": "Vorlux AI | Content Calendar Generator",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "weeks", "weeksInterval": 1 }] }
      },
      "id": "schedule-trigger",
      "name": "Weekly Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/studio/topics",
        "method": "GET",
        "options": { "timeout": 10000 }
      },
      "id": "fetch-topics",
      "name": "Fetch Trending Topics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 200]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/analytics/dashboard",
        "method": "GET",
        "options": { "timeout": 10000 }
      },
      "id": "fetch-analytics",
      "name": "Fetch Content Analytics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 400]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const topics = $('Fetch Trending Topics').first().json.data || $('Fetch Trending Topics').first().json.topics || [];\nconst analytics = $('Fetch Content Analytics').first().json;\n\nconst days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];\nconst contentTypes = ['blog', 'video', 'social', 'podcast', 'newsletter', 'stream', 'community'];\n\nconst calendar = days.map((day, i) => {\n  const topic = topics[i % topics.length] || { title: 'General Content' };\n  return {\n    day,\n    date: new Date(Date.now() + (i + 1) * 86400000).toISOString().split('T')[0],\n    contentType: contentTypes[i % contentTypes.length],\n    topic: topic.title || topic.name || 'TBD',\n    status: 'planned',\n    assignedAgent: 'content-writer',\n    notes: ''\n  };\n});\n\nreturn [{ json: { weekOf: new Date().toISOString().split('T')[0], calendar, totalSlots: calendar.length, generatedAt: new Date().toISOString() } }];"
      },
      "id": "generate-calendar",
      "name": "Generate Weekly Calendar",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [720, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/calendar",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'content-calendar', entries: $json.calendar }) }}",
        "options": { "timeout": 15000 }
      },
      "id": "save-calendar",
      "name": "Save to Hub Calendar",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [960, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_CONTENT_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: '📅 **Weekly Content Calendar Generated**\\nWeek of: ' + $('Generate Weekly Calendar').first().json.weekOf + '\\nSlots: ' + $('Generate Weekly Calendar').first().json.totalSlots + '\\n\\n' + $('Generate Weekly Calendar').first().json.calendar.map(c => '• ' + c.day + ': [' + c.contentType + '] ' + c.topic).join('\\n') }) }}"
      },
      "id": "discord-notify",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1200, 300]
    }
  ],
  "connections": {
    "Weekly Schedule": { "main": [[{ "node": "Fetch Trending Topics", "type": "main", "index": 0 }, { "node": "Fetch Content Analytics", "type": "main", "index": 0 }]] },
    "Fetch Trending Topics": { "main": [[{ "node": "Generate Weekly Calendar", "type": "main", "index": 0 }]] },
    "Fetch Content Analytics": { "main": [[{ "node": "Generate Weekly Calendar", "type": "main", "index": 0 }]] },
    "Generate Weekly Calendar": { "main": [[{ "node": "Save to Hub Calendar", "type": "main", "index": 0 }]] },
    "Save to Hub Calendar": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
