{
  "name": "Rodopi Dent - Daily Backup",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 23,
              "triggerAtMinute": 0
            }
          ]
        }
      },
      "id": "schedule",
      "name": "Daily at 23:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1hv4XAfHhScA40Bm1kQ3I-Ih4SJuCBpOJxTOYDNb167g"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Appointments"
        },
        "options": {
          "returnAllMatches": true
        }
      },
      "id": "read-appointments",
      "name": "Read Appointments",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        -150
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1hv4XAfHhScA40Bm1kQ3I-Ih4SJuCBpOJxTOYDNb167g"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Finance"
        },
        "options": {
          "returnAllMatches": true
        }
      },
      "id": "read-finance",
      "name": "Read Finance",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1hv4XAfHhScA40Bm1kQ3I-Ih4SJuCBpOJxTOYDNb167g"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Settings"
        },
        "options": {
          "returnAllMatches": true
        }
      },
      "id": "read-settings",
      "name": "Read Settings",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        150
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Collect all data from previous nodes\nconst appointments = $('Read Appointments').all().map(i => i.json);\nconst finance = $('Read Finance').all().map(i => i.json);\nconst settings = $('Read Settings').all().map(i => i.json);\n\nconst today = new Date();\nconst dateStr = today.toISOString().split('T')[0];\nconst timeStr = today.toISOString().split('T')[1].substring(0, 8).replace(/:/g, '-');\n\nconst backup = {\n  backupDate: today.toISOString(),\n  fileName: `rodopi-dent-backup-${dateStr}_${timeStr}.json`,\n  data: {\n    appointments: appointments,\n    finance: finance,\n    settings: settings\n  },\n  stats: {\n    appointmentsCount: appointments.length,\n    financeCount: finance.length,\n    settingsCount: settings.length\n  }\n};\n\nreturn [{ json: backup }];"
      },
      "id": "merge-data",
      "name": "Merge All Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        0
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "name": "={{ $json.fileName }}",
        "options": {},
        "inputDataFieldName": "={{ JSON.stringify($json.data) }}"
      },
      "id": "upload-drive",
      "name": "Upload to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        720,
        0
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Log backup completion\nconst backup = $('Merge All Data').first().json;\nconst driveResult = $('Upload to Drive').first().json;\n\nconsole.log(`Backup completed: ${backup.fileName}`);\nconsole.log(`Stats: ${JSON.stringify(backup.stats)}`);\n\nreturn [{\n  json: {\n    success: true,\n    fileName: backup.fileName,\n    stats: backup.stats,\n    driveFileId: driveResult.id || 'N/A',\n    completedAt: new Date().toISOString()\n  }\n}];"
      },
      "id": "log-result",
      "name": "Log Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        0
      ]
    }
  ],
  "connections": {
    "Daily at 23:00": {
      "main": [
        [
          {
            "node": "Read Appointments",
            "type": "main",
            "index": 0
          },
          {
            "node": "Read Finance",
            "type": "main",
            "index": 0
          },
          {
            "node": "Read Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointments": {
      "main": [
        [
          {
            "node": "Merge All Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Finance": {
      "main": [
        [
          {
            "node": "Merge All Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Settings": {
      "main": [
        [
          {
            "node": "Merge All Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Data": {
      "main": [
        [
          {
            "node": "Upload to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Drive": {
      "main": [
        [
          {
            "node": "Log Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "Rodopi Dent"
    }
  ]
}