{
  "name": "Vorlux AI | VTuber Config Sync",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "hours", "hoursInterval": 1 }] }
      },
      "id": "schedule-trigger",
      "name": "Every Hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/vtuber/characters",
        "method": "GET",
        "options": { "timeout": 15000 }
      },
      "id": "fetch-vtuber-chars",
      "name": "Fetch VTuber Characters",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/vtuber/status",
        "method": "GET",
        "options": { "timeout": 15000 }
      },
      "id": "fetch-vtuber-status",
      "name": "Fetch VTuber Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 500]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const chars = $('Fetch VTuber Characters').first().json;\nconst status = $('Fetch VTuber Status').first().json;\nconst configs = (chars.characters || chars.data || []).map(c => ({\n  id: c.id,\n  name: c.name || c.display_name,\n  model: c.model_path || c.model,\n  expressions: c.expressions || [],\n  active: c.active !== false,\n  lastSync: new Date().toISOString()\n}));\nconst platformStatus = status.connected || status.status || 'unknown';\nreturn [{ json: { configs, platformStatus, syncedAt: new Date().toISOString(), count: configs.length } }];"
      },
      "id": "merge-configs",
      "name": "Merge & Compare Configs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [680, 400]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/vtuber/platform-sync",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ configs: $json.configs, syncedAt: $json.syncedAt }) }}",
        "options": { "timeout": 30000 }
      },
      "id": "push-sync",
      "name": "Push Sync to Platform",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [920, 400]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: '🔄 VTuber Config Sync complete — ' + $('Merge & Compare Configs').first().json.count + ' characters synced at ' + $('Merge & Compare Configs').first().json.syncedAt }) }}"
      },
      "id": "discord-notify",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1160, 400]
    }
  ],
  "connections": {
    "Every Hour": { "main": [[{ "node": "Fetch VTuber Characters", "type": "main", "index": 0 }, { "node": "Fetch VTuber Status", "type": "main", "index": 0 }]] },
    "Fetch VTuber Characters": { "main": [[{ "node": "Merge & Compare Configs", "type": "main", "index": 0 }]] },
    "Fetch VTuber Status": { "main": [[{ "node": "Merge & Compare Configs", "type": "main", "index": 0 }]] },
    "Merge & Compare Configs": { "main": [[{ "node": "Push Sync to Platform", "type": "main", "index": 0 }]] },
    "Push Sync to Platform": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
