{
  "name": "FlipOps Discovery - Property Sources",
  "nodes": [
    {
      "parameters": {},
      "name": "Manual Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyDay",
              "hour": 2,
              "minute": 0
            }
          ]
        }
      },
      "name": "Daily at 2AM",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        250,
        500
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "1TwEzCOn-2FygrJ3jSTixzXgdknMmn-I_AiuHaCPjJKY",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Properties",
          "mode": "name"
        },
        "options": {}
      },
      "name": "Read Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 2,
      "position": [
        450,
        400
      ]
    },
    {
      "parameters": {
        "functionCode": "// Normalize Google Sheets data to FlipOps format\nreturn items.map(item => {\n  const data = item.json;\n  \n  // Calculate property score\n  let score = 50; // Base score\n  if (data.foreclosure === true || data.foreclosure === 'true') score += 25;\n  if (data.preForeclosure === true || data.preForeclosure === 'true') score += 20;\n  if (data.taxDelinquent === true || data.taxDelinquent === 'true') score += 15;\n  if (data.vacant === true || data.vacant === 'true') score += 10;\n  if (data.absenteeOwner === true || data.absenteeOwner === 'true') score += 5;\n  if (data.bankruptcy === true || data.bankruptcy === 'true') score += 8;\n  score = Math.min(score, 100); // Cap at 100\n  \n  return {\n    json: {\n      type: 'property',\n      action: 'create',\n      source: 'google-sheets',\n      workflowName: 'Property Discovery',\n      data: {\n        address: data.address || '',\n        city: data.city || '',\n        state: data.state || '',\n        zip: data.zip || '',\n        ownerName: data.ownerName || data.owner || null,\n        assessedValue: parseFloat(data.assessedValue) || 0,\n        taxDelinquent: data.taxDelinquent === true || data.taxDelinquent === 'true',\n        foreclosure: data.foreclosure === true || data.foreclosure === 'true',\n        preForeclosure: data.preForeclosure === true || data.preForeclosure === 'true',\n        vacant: data.vacant === true || data.vacant === 'true',\n        bankruptcy: data.bankruptcy === true || data.bankruptcy === 'true',\n        absenteeOwner: data.absenteeOwner === true || data.absenteeOwner === 'true',\n        dataSource: 'Google Sheets',\n        score: score,\n        importedAt: new Date().toISOString()\n      }\n    }\n  };\n});"
      },
      "name": "Format for API",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        400
      ]
    },
    {
      "parameters": {
        "batchSize": 10,
        "options": {}
      },
      "name": "Batch Properties",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        850,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://flipops-api-production.up.railway.app/api/webhooks/n8n",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-api-key",
              "value": "fo_live_10177805c8d743e1a6e1860515dc2b3f"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": []
        },
        "options": {
          "timeout": 30000
        }
      },
      "name": "Send to FlipOps API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1050,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json.data.score}}",
              "operation": "largerEqual",
              "value2": 80
            }
          ]
        }
      },
      "name": "High Score?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1250,
        400
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "channel": "C09JDCY5SKH",
        "text": "=\ud83d\udd25 *High Score Property Alert!*\\n\\nScore: {{$json.data.score}}/100\\nAddress: {{$json.data.address}}, {{$json.data.city}}, {{$json.data.state}}\\nOwner: {{$json.data.ownerName}}\\n\\nFlags:\\n\u2022 Foreclosure: {{$json.data.foreclosure}}\\n\u2022 Tax Delinquent: {{$json.data.taxDelinquent}}\\n\u2022 Vacant: {{$json.data.vacant}}",
        "otherOptions": {}
      },
      "name": "Alert High Score",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [
        1450,
        350
      ]
    },
    {
      "parameters": {
        "resume": "timeInterval",
        "amount": 1,
        "unit": "seconds"
      },
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1250,
        550
      ]
    }
  ],
  "connections": {
    "Manual Start": {
      "main": [
        [
          {
            "node": "Read Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily at 2AM": {
      "main": [
        [
          {
            "node": "Read Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Google Sheet": {
      "main": [
        [
          {
            "node": "Format for API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format for API": {
      "main": [
        [
          {
            "node": "Batch Properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Batch Properties": {
      "main": [
        [
          {
            "node": "Send to FlipOps API",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to FlipOps API": {
      "main": [
        [
          {
            "node": "High Score?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "High Score?": {
      "main": [
        [
          {
            "node": "Alert High Score",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Batch Properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Batch Properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {}
}