{
  "name": "Premium Landscapes - AI Garden Design Generator",
  "nodes": [
    {
      "parameters": {
        "path": "premium-landscapes-design",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "1",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        380
      ],
      "notesInFlow": true,
      "notes": "Receives POST from website with customer and design details"
    },
    {
      "parameters": {
        "functionCode": "const customer = $json.customer;\nconst design = $json.design;\nif (!customer || !customer.email) throw new Error('Customer email required');\nif (!design || !design.features || !design.styleDescription) throw new Error('Design info incomplete');\nconst clean = {\n  email: customer.email.trim().toLowerCase(),\n  phone: customer.phone || '',\n  features: design.features,\n  styleDescription: design.styleDescription.trim(),\n  gardenSize: design.gardenSize || 'Not specified',\n  budget: design.budget || 'Not specified',\n  timestamp: $json.metadata?.timestamp || new Date().toISOString()\n};\nreturn [clean];"
      },
      "id": "2",
      "name": "Validate & Parse Input",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        520,
        380
      ]
    },
    {
      "parameters": {
        "functionCode": "const f = $json.features;\nconst s = $json.styleDescription;\nconst g = $json.gardenSize;\nconst featureMap = { patio:'Natural stone patio', decking:'Composite decking', lawn:'Manicured lawn', 'water-feature':'Water feature', 'garden-beds':'Planted beds', seating:'Outdoor seating', pergola:'Pergola', lighting:'Lighting scheme', 'full-redesign':'Complete redesign' };\nconst featureList = f.map(x=>featureMap[x]||x).join(', ');\nconst prompts=[];\nconst base = { email:$json.email, phone:$json.phone, features:f, style:s, garden:g, budget:$json.budget };\nconst variants=[\n  {variation:'Classic',prompt:`Create a photorealistic UK garden design for ${g}. Style: ${s}. Include: ${featureList}. Natural lighting, realistic proportions, 4K render.`},\n  {variation:'Modern',prompt:`Design a modern UK garden (${g}) in ${s} style. Include ${featureList}. Emphasize clean lines, sustainable plants, 4K architectural render.`},\n  {variation:'Lush',prompt:`Visualize a lush inviting garden (${g}) reflecting ${s}. Include ${featureList}. Photographic realism, rich planting, vibrant textures, 4K image.`}\n];\nvariants.forEach((v,i)=>prompts.push({...base,...v,designNumber:i+1}));\nreturn prompts;"
      },
      "id": "3",
      "name": "Build DALL-E Prompts",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        380
      ]
    },
    {
      "parameters": {
        "url": "https://api.openai.com/v1/images/generations",
        "method": "POST",
        "authentication": "predefinedCredentialType",
        "jsonParameters": true,
        "options": {
          "responseFormat": "json",
          "timeout": 120000
        },
        "bodyParametersJson": "{\n  \"model\": \"dall-e-3\",\n  \"prompt\": \"={{$json.prompt}}\",\n  \"n\": 1,\n  \"size\": \"1792x1024\",\n  \"quality\": \"hd\",\n  \"response_format\": \"b64_json\"\n}"
      },
      "id": "4",
      "name": "Generate AI Design",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1080,
        380
      ],
      "notesInFlow": true,
      "notes": "Generates one design per loop using DALL-E 3"
    },
    {
      "parameters": {
        "functionCode": "const img=$json.data[0].b64_json;return [{designNumber:$json.designNumber,variation:$json.variation,imageBase64:img,imageCid:`design${$json.designNumber}@premium-landscapes`,email:$json.email,phone:$json.phone,features:$json.features,style:$json.styleDescription,garden:$json.gardenSize,budget:$json.budget}];"
      },
      "id": "5",
      "name": "Process Image Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1360,
        380
      ],
      "notesInFlow": true,
      "notes": "Converts API response into usable base64 image with CID"
    },
    {
      "parameters": {
        "mode": "mergeAllItems"
      },
      "id": "6",
      "name": "Aggregate All Designs",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1640,
        380
      ],
      "notesInFlow": true,
      "notes": "Combines all 3 design outputs into a single object"
    },
    {
      "parameters": {
        "functionCode": "const d=$json;\nconst html=`<!DOCTYPE html><html><body style='font-family:Arial;background:#f5f5f5;padding:30px;'>\n<div style='background:#fff;padding:40px;border-radius:12px;max-width:700px;margin:auto;'>\n<div style='text-align:center;border-bottom:3px solid #2563eb;padding-bottom:20px;'>\n<img src='https://www.premium-landscapes.co.uk/logo.png' style='max-width:200px;'>\n<h2 style='color:#2563eb;'>Your AI Garden Designs Are Ready</h2></div>\n<p>We\u2019ve created 3 unique AI-generated design concepts based on your preferences.</p>\n<h3 style='color:#2563eb;'>Design Summary</h3>\n<p><b>Style:</b> ${d[0].style}</p>\n<p><b>Features:</b> ${d[0].features.join(', ')}</p>\n<p><b>Garden Size:</b> ${d[0].garden}</p>\n<p><b>Budget:</b> ${d[0].budget}</p>\n${d.map((x,i)=>`<div style='margin:40px 0;text-align:center;'><h3>Design ${i+1}: ${x.variation}</h3><img src='cid:${x.imageCid}' style='width:100%;border-radius:10px;box-shadow:0 4px 6px rgba(0,0,0,0.2);margin-top:15px;'></div>`).join('')}\n<div style='text-align:center;margin-top:40px;'>\n<a href='https://www.premium-landscapes.co.uk/quote.html' style='background:#2563eb;color:white;padding:15px 30px;text-decoration:none;border-radius:50px;font-weight:bold;'>Get Instant Quote \u2192</a>\n</div>\n<p style='text-align:center;font-size:13px;color:#666;margin-top:30px;'>Premium Landscapes \u00b7 07444 887813 \u00b7 info@premium-landscapes.co.uk<br>www.premium-landscapes.co.uk</p>\n</div></body></html>`;\nreturn [{html:html,customerEmail:d[0].email,designs:d,subject:'Your AI Garden Designs from Premium Landscapes \ud83c\udf3f'}];"
      },
      "id": "7",
      "name": "Build Email HTML",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1920,
        380
      ],
      "notesInFlow": true,
      "notes": "Generates branded HTML email embedding all 3 designs"
    },
    {
      "parameters": {
        "fromEmail": "info@premium-landscapes.co.uk",
        "toEmail": "={{$json.customerEmail}}",
        "subject": "={{$json.subject}}",
        "emailFormat": "html",
        "body": "={{$json.html}}",
        "attachments": [
          {
            "property": "designs[0].imageBase64",
            "fileName": "design-1.png",
            "contentId": "={{$json.designs[0].imageCid}}",
            "mimeType": "image/png",
            "encoding": "base64"
          },
          {
            "property": "designs[1].imageBase64",
            "fileName": "design-2.png",
            "contentId": "={{$json.designs[1].imageCid}}",
            "mimeType": "image/png",
            "encoding": "base64"
          },
          {
            "property": "designs[2].imageBase64",
            "fileName": "design-3.png",
            "contentId": "={{$json.designs[2].imageCid}}",
            "mimeType": "image/png",
            "encoding": "base64"
          }
        ]
      },
      "id": "8",
      "name": "Send Email with Embedded Images",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        2220,
        380
      ],
      "notesInFlow": true,
      "notes": "Sends the HTML email with all 3 inline images via Gmail OAuth2"
    },
    {
      "parameters": {
        "url": "https://hooks.airtable.com/PLACEHOLDER",
        "method": "POST",
        "jsonParameters": true,
        "sendBody": true,
        "bodyParametersJson": "{\n  \"email\": \"={{$json.customerEmail}}\",\n  \"features\": \"={{$json.designs[0].features.join(', ')}}\",\n  \"style\": \"={{$json.designs[0].style}}\",\n  \"garden_size\": \"={{$json.designs[0].garden}}\",\n  \"budget\": \"={{$json.designs[0].budget}}\",\n  \"timestamp\": \"={{$now}}\",\n  \"source\": \"AI Garden Design\",\n  \"status\": \"Design Sent\"\n}",
        "options": {},
        "disableExecution": true
      },
      "id": "9",
      "name": "Log to CRM (Optional)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        2500,
        380
      ],
      "notesInFlow": true,
      "notes": "Optional Airtable/Zapier logging node \u2013 disabled by default"
    },
    {
      "parameters": {
        "responseBody": "{\n  \"success\": true,\n  \"message\": \"AI designs generated and sent successfully\",\n  \"designsGenerated\": 3,\n  \"email\": \"={{$json.customerEmail}}\"\n}"
      },
      "id": "10",
      "name": "Return Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2780,
        380
      ],
      "notesInFlow": true,
      "notes": "Returns success response to website after email is sent"
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Validate & Parse Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate & Parse Input": {
      "main": [
        [
          {
            "node": "Build DALL-E Prompts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build DALL-E Prompts": {
      "main": [
        [
          {
            "node": "Generate AI Design",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate AI Design": {
      "main": [
        [
          {
            "node": "Process Image Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Image Data": {
      "main": [
        [
          {
            "node": "Aggregate All Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate All Designs": {
      "main": [
        [
          {
            "node": "Build Email HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Email HTML": {
      "main": [
        [
          {
            "node": "Send Email with Embedded Images",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email with Embedded Images": {
      "main": [
        [
          {
            "node": "Log to CRM (Optional)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to CRM (Optional)": {
      "main": [
        [
          {
            "node": "Return Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1"
}