{
  "name": "Low Stock Alert - DeepSolution",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{$env.DEEPSOLUTION_API_URL}}/api/trpc/inventory.getLowStockAlerts",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "get-low-stock",
      "name": "Get Low Stock Alerts",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        470,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-1",
              "leftValue": "={{ $json.result.data.length }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-has-alerts",
      "name": "Has Alerts?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        690,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "alert-summary",
              "name": "alertSummary",
              "value": "={{ $json.result.data.map(a => `\u2022 ${a.productName}: ${a.currentStock} \u0645\u062a\u0628\u0642\u064a (\u062d\u062f: ${a.reorderLevel})`).join('\\n') }}",
              "type": "string"
            },
            {
              "id": "critical-count",
              "name": "criticalCount",
              "value": "={{ $json.result.data.filter(a => a.severity === 'critical').length }}",
              "type": "number"
            },
            {
              "id": "warning-count",
              "name": "warningCount",
              "value": "={{ $json.result.data.filter(a => a.severity === 'warning').length }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "format-message",
      "name": "Format Message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        910,
        200
      ]
    },
    {
      "parameters": {
        "sendTo": "={{$env.ADMIN_EMAIL}}",
        "subject": "\ud83d\udea8 \u062a\u0646\u0628\u064a\u0647 \u0645\u062e\u0632\u0648\u0646 \u0645\u0646\u062e\u0641\u0636 - DeepSolution",
        "message": "=\u0645\u0631\u062d\u0628\u0627\u064b\u060c\n\n\u064a\u0648\u062c\u062f \u0645\u0646\u062a\u062c\u0627\u062a \u0628\u0645\u062e\u0632\u0648\u0646 \u0645\u0646\u062e\u0641\u0636 \u062a\u062d\u062a\u0627\u062c \u0627\u0646\u062a\u0628\u0627\u0647\u0643:\n\n\ud83d\udd34 \u062d\u0631\u062c: {{ $json.criticalCount }} \u0645\u0646\u062a\u062c\n\ud83d\udfe1 \u062a\u062d\u0630\u064a\u0631: {{ $json.warningCount }} \u0645\u0646\u062a\u062c\n\n\u0627\u0644\u062a\u0641\u0627\u0635\u064a\u0644:\n{{ $json.alertSummary }}\n\n---\n\u0647\u0630\u0627 \u062a\u0646\u0628\u064a\u0647 \u062a\u0644\u0642\u0627\u0626\u064a \u0645\u0646 \u0646\u0638\u0627\u0645 DeepSolution",
        "options": {}
      },
      "id": "send-email",
      "name": "Send Email Alert",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1130,
        200
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "no-op",
      "name": "No Alerts",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        910,
        400
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Low Stock Alerts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Low Stock Alerts": {
      "main": [
        [
          {
            "node": "Has Alerts?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Alerts?": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Alerts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Send Email Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "inventory",
    "alerts",
    "automation"
  ],
  "triggerCount": 1,
  "updatedAt": "2025-01-01T00:00:00.000Z",
  "versionId": "1"
}