{
  "name": "Pazarlama · Aylık konut bülteni",
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "months", "triggerAtDayOfMonth": 1, "triggerAtHour": 9 }] }
      },
      "id": "b2c3d4e5-0001-4000-8000-000000000001",
      "name": "Her ayın 1'i, 09:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [0, 300]
    },
    {
      "parameters": {
        "url": "={{ $env.SITE_URL }}/wp-json/wp/v2/uzun-donem?status=publish&per_page=100",
        "options": {}
      },
      "id": "b2c3d4e5-0002-4000-8000-000000000002",
      "name": "Müsait ilanları çek",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "jsCode": "// İlanları projeye göre grupla; her proje için başlangıç fiyatı, tipolojiler, ilçe ve fotoğraflar\nconst byProject = {};\nfor (const { json: i } of $input.all()) {\n  const p = (byProject[i.proje] ??= { proje: i.proje, ilce: i.ilce, fiyatlar: [], tipler: new Set(), bina: i.bina_foto, ic: i.ic_foto, link: i.link });\n  p.fiyatlar.push(Number(i.aylik_fiyat));\n  p.tipler.add(i.oda_tipi);\n}\nreturn Object.values(byProject)\n  .map((p) => ({ json: { ...p, baslangic: Math.min(...p.fiyatlar), tipler: [...p.tipler].join(' / '), adet: p.fiyatlar.length } }))\n  .sort((a, b) => b.json.adet - a.json.adet)\n  .slice(0, 4);"
      },
      "id": "b2c3d4e5-0003-4000-8000-000000000003",
      "name": "Projeye göre grupla, 4 proje seç",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.anthropic.com/v1/messages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "anthropicApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"claude-sonnet-5\",\n  \"max_tokens\": 400,\n  \"system\": \"Konut bülteni için Türkçe konu satırı (en fazla 60 karakter) ve 2 cümlelik giriş yaz. Yalnızca verilen bilgileri kullan, rakam uydurma. JSON döndür: konu, giris.\",\n  \"messages\": [{ \"role\": \"user\", \"content\": {{ JSON.stringify(JSON.stringify($input.all().map(i => i.json))) }} }]\n}",
        "options": {}
      },
      "id": "b2c3d4e5-0004-4000-8000-000000000004",
      "name": "Claude AI · konu ve giriş metni",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 300]
    },
    {
      "parameters": {
        "operation": "generateHtmlTemplate",
        "html": "<!-- Beyaz etiket bülten şablonu: marka, konu, giriş ve 4 proje kartı burada doldurulur -->\n<div>{{ $json.giris }}</div>"
      },
      "id": "b2c3d4e5-0005-4000-8000-000000000005",
      "name": "Beyaz etiket şablonu doldur",
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [960, 300]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "pazarlama@sirket.com",
        "subject": "=Bülten onayı: {{ $('Claude AI · konu ve giriş metni').item.json.konu }}",
        "message": "=Bu ayın bülteni hazır. Önizleme ektedir; onaylarsanız liste gönderimine geçilecek.",
        "approvalOptions": { "values": { "approvalType": "double" } },
        "options": {}
      },
      "id": "b2c3d4e5-0006-4000-8000-000000000006",
      "name": "Pazarlama onayı",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1200, 300],
      "webhookId": "c8d2f3a1-0006-4000-8000-000000000006"
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.data.approved }}",
              "rightValue": true,
              "operator": { "type": "boolean", "operation": "true", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b2c3d4e5-0007-4000-8000-000000000007",
      "name": "Onaylandı mı?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1440, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.MAIL_SERVICE_URL }}/campaigns",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"subject\": \"{{ $('Claude AI · konu ve giriş metni').item.json.konu }}\",\n  \"html\": {{ JSON.stringify($('Beyaz etiket şablonu doldur').item.json.html) }},\n  \"list\": \"bulten-abonleri\"\n}",
        "options": {}
      },
      "id": "b2c3d4e5-0008-4000-8000-000000000008",
      "name": "Abone listesine gönder",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1680, 220]
    },
    {
      "parameters": {
        "resource": "worksheet",
        "operation": "append",
        "workbook": { "__rl": true, "mode": "list", "value": "" },
        "worksheet": { "__rl": true, "mode": "list", "value": "" },
        "dataMode": "autoMap",
        "options": {}
      },
      "id": "b2c3d4e5-0009-4000-8000-000000000009",
      "name": "Gönderim kaydı",
      "type": "n8n-nodes-base.microsoftExcel",
      "typeVersion": 2.1,
      "position": [1920, 300]
    }
  ],
  "connections": {
    "Her ayın 1'i, 09:00": { "main": [[{ "node": "Müsait ilanları çek", "type": "main", "index": 0 }]] },
    "Müsait ilanları çek": { "main": [[{ "node": "Projeye göre grupla, 4 proje seç", "type": "main", "index": 0 }]] },
    "Projeye göre grupla, 4 proje seç": { "main": [[{ "node": "Claude AI · konu ve giriş metni", "type": "main", "index": 0 }]] },
    "Claude AI · konu ve giriş metni": { "main": [[{ "node": "Beyaz etiket şablonu doldur", "type": "main", "index": 0 }]] },
    "Beyaz etiket şablonu doldur": { "main": [[{ "node": "Pazarlama onayı", "type": "main", "index": 0 }]] },
    "Pazarlama onayı": { "main": [[{ "node": "Onaylandı mı?", "type": "main", "index": 0 }]] },
    "Onaylandı mı?": {
      "main": [
        [{ "node": "Abone listesine gönder", "type": "main", "index": 0 }],
        [{ "node": "Gönderim kaydı", "type": "main", "index": 0 }]
      ]
    },
    "Abone listesine gönder": { "main": [[{ "node": "Gönderim kaydı", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "pinData": {}
}
