{
  "name": "ConfortPlace - Rental Lead Agent (MVP)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "confortplace-messenger",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "messenger-webhook",
      "name": "Messenger Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "content": "Architecture placeholder for an official Facebook Page webhook. Add signature verification and Meta credentials before activation. Flow: Normalize -> Extract -> Match -> Reply Draft -> Stage -> Scheduling.",
        "height": 160,
        "width": 400
      },
      "id": "lead-note",
      "name": "Implementation Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -240
      ]
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body || $json; return [{ json: { lead_id: body.lead_id || `LEAD-${Date.now()}`, name: body.name || 'Lead', source: 'facebook_page', contact_channel: 'messenger', original_message: body.message || '', room_type_needed: body.room_type_needed || null, parking_needed: body.parking_needed ?? null, budget: body.budget ?? null, move_in_date: body.move_in_date || null, number_of_people: body.number_of_people ?? null, preferred_location: body.preferred_location || null, pets: body.pets ?? null, wants_visit: body.wants_visit ?? null, matched_rooms: [], stage: 'new', last_message_at: new Date().toISOString(), calendar_event_id: null, notes: 'MVP normalized input' } }];"
      },
      "id": "normalize-extract",
      "name": "Normalize + Extract Requirements (Mock)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $env.API_BASE_URL || 'http://host.docker.internal:3000' }}/rooms/match",
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "match-rooms",
      "name": "Match Rooms",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        500,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => ({ json: { matches: item.json.data || [], reply_status: 'draft_pending_approval', lead_stage: (item.json.data || []).length ? 'options_sent' : 'qualified', scheduling_triggered: false } }));"
      },
      "id": "reply-stage",
      "name": "Generate Reply + Update Stage",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        750,
        0
      ]
    }
  ],
  "connections": {
    "Messenger Webhook": {
      "main": [
        [
          {
            "node": "Normalize + Extract Requirements (Mock)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize + Extract Requirements (Mock)": {
      "main": [
        [
          {
            "node": "Match Rooms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Rooms": {
      "main": [
        [
          {
            "node": "Generate Reply + Update Stage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Toronto"
  },
  "versionId": "22222222-2222-4222-8222-222222222222",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}