{
  "id": "waTenantGroupRemindersV2",
  "name": "ConfortPlace - WhatsApp Tenant Group Reminders V2 (Draft + Approval)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "id": "half-hour-trigger",
      "name": "Every 30 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "content": "SAFE MVP: creates human-reviewed WhatsApp group drafts only. It does not automate WhatsApp Web or a personal account. Garbage schedules remain inactive until their real collection days are configured. Future sending must use an authorized official Groups API account, verified opt-in and an approved template when required.",
        "height": 210,
        "width": 440,
        "color": 5
      },
      "id": "safety-note",
      "name": "Safety and Configuration",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -280
      ]
    },
    {
      "parameters": {
        "jsCode": "const parts = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Toronto', weekday: 'long', hour: '2-digit', minute: '2-digit', hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(new Date());\nconst value = type => parts.find(part => part.type === type)?.value;\nconst minute = Number(value('minute')) < 30 ? '00' : '30';\nreturn [{ json: { weekday: value('weekday'), time: `${value('hour')}:${minute}`, date_key: `${value('year')}-${value('month')}-${value('day')}`, timezone: 'America/Toronto', correlation_id: $execution.id } }];"
      },
      "id": "local-time",
      "name": "Resolve Toronto Time",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ 'http://api:3000/reminders/whatsapp/due?weekday=' + $json.weekday + '&time=' + $json.time }}",
        "options": {}
      },
      "id": "get-due",
      "name": "Read Due Reminder Schedules",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const dateKey = $('Resolve Toronto Time').first().json.date_key;\nreturn ($json.data || []).map(schedule => ({ json: { ...schedule, date_key: dateKey } }));"
      },
      "id": "split-schedules",
      "name": "One Item per House Reminder",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        0
      ]
    },
    {
      "parameters": {
        "url": "http://api:3000/reminders/whatsapp/generate-draft",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify({ schedule_id: $json.schedule_id, date_key: $json.date_key }) }}",
        "options": {}
      },
      "id": "generate-draft",
      "name": "Generate Human-Style Draft",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => ({ json: { ...item.json.data, approval_status: 'pending', created_at: new Date().toISOString(), instruction: 'Review and copy/paste this draft into the named WhatsApp group.' } }));"
      },
      "id": "approval-queue",
      "name": "Create Manual Approval Task",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1210,
        0
      ]
    },
    {
      "parameters": {},
      "id": "official-send-placeholder",
      "name": "Official Groups API Send (FUTURE - DISABLED)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1460,
        0
      ],
      "disabled": true
    }
  ],
  "connections": {
    "Every 30 Minutes": {
      "main": [
        [
          {
            "node": "Resolve Toronto Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Toronto Time": {
      "main": [
        [
          {
            "node": "Read Due Reminder Schedules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Due Reminder Schedules": {
      "main": [
        [
          {
            "node": "One Item per House Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One Item per House Reminder": {
      "main": [
        [
          {
            "node": "Generate Human-Style Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Human-Style Draft": {
      "main": [
        [
          {
            "node": "Create Manual Approval Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Toronto"
  },
  "versionId": "44444444-4444-4444-8444-444444444444",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}