{
  "nodes": [
    {
      "id": "c5a9c89a-3fcc-4bcb-aca8-5a2692eb4d7a",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -450,
        150
      ],
      "parameters": {}
    },
    {
      "id": "dce234e9-ca46-4fc1-a332-c86541ef3e58",
      "name": "Fetch Google Sheet Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -208,
        150
      ],
      "parameters": {
        "sheetId": "$env.GOOGLE_SHEET_ID",
        "range": "A1:E"
      }
    },
    {
      "id": "f189c65d-c8c5-4cbf-8af2-5e6c8c29771f",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        100,
        150
      ],
      "parameters": {
        "batchSize": 1
      }
    },
    {
      "id": "21349b58-a1ab-4204-b8b4-3ba8f5500e75",
      "name": "AI Analysis",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        300,
        150
      ],
      "parameters": {
        "model": "$env.AZURE_OPENAI_MODEL",
        "prompt": "Analysiere die folgenden Gründe für gewonnen/verlorene Deals: {{$json[\"dealReasons\"]}}"
      }
    },
    {
      "id": "f54f4d8d-975a-4bb6-8277-6cfa6c121c25",
      "name": "Parse AI Response",
      "type": "n8n-nodes-base.code",
      "position": [
        500,
        150
      ],
      "parameters": {
        "functionCode": "return JSON.parse($input.item[0].json.response);"
      }
    },
    {
      "id": "3fdc1413-d3ef-4494-9c02-2cc40fe34bcf",
      "name": "Save to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        700,
        150
      ],
      "parameters": {
        "sheetId": "$env.GOOGLE_SHEET_ID",
        "range": "A1:E",
        "values": [
          [
            "{{$json[\"winReasons\"]}}",
            "{{$json[\"lossReasons\"]}}"
          ]
        ]
      }
    },
    {
      "id": "c76e86be-df1b-409e-8242-6222ce7216b3",
      "name": "Send Email Digest",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        900,
        150
      ],
      "parameters": {
        "fromEmail": "$env.FROM_EMAIL",
        "toEmail": "$env.TO_EMAIL",
        "subject": "Wöchentlicher Vertriebsbericht",
        "text": "Hier sind die aktuellen Ergebnisse der Deal-Analyse der Woche."
      }
    }
  ],
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Fetch Google Sheet Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Google Sheet Data": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "AI Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Analysis": {
      "main": [
        [
          {
            "node": "Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Sheets": {
      "main": [
        [
          {
            "node": "Send Email Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}