{
  "name": "WasslChat - Low Stock Alert to Owner",
  "nodes": [
    {
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        250,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      }
    },
    {
      "name": "Get Low Stock",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        450,
        300
      ],
      "parameters": {
        "url": "={{ $env.WASSLCHAT_API_URL }}/api/v1/products/low-stock",
        "method": "GET"
      }
    },
    {
      "name": "Check Count",
      "type": "n8n-nodes-base.if",
      "position": [
        650,
        300
      ],
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.length }}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      }
    },
    {
      "name": "Format Alert",
      "type": "n8n-nodes-base.set",
      "position": [
        850,
        300
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "alert",
              "value": "\u26a0\ufe0f \u062a\u0646\u0628\u064a\u0647 \u0645\u062e\u0632\u0648\u0646 \u0645\u0646\u062e\u0641\u0636!\n\n\u0627\u0644\u0645\u0646\u062a\u062c\u0627\u062a \u0627\u0644\u062a\u0627\u0644\u064a\u0629 \u0642\u0627\u0631\u0628\u062a \u0639\u0644\u0649 \u0627\u0644\u0646\u0641\u0627\u062f:\n{{ $json.map(p => `\u2022 ${p.nameAr || p.name}: ${p.inventoryQuantity} \u0642\u0637\u0639\u0629`).join('\\n') }}\n\n\u064a\u0631\u062c\u0649 \u0625\u0639\u0627\u062f\u0629 \u0627\u0644\u062a\u062e\u0632\u064a\u0646 \u0641\u064a \u0623\u0642\u0631\u0628 \u0648\u0642\u062a \ud83d\udce6"
            }
          ]
        }
      }
    },
    {
      "name": "Notify Owner",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1050,
        300
      ],
      "parameters": {
        "url": "={{ $env.WASSLCHAT_API_URL }}/api/v1/whatsapp/send/text",
        "method": "POST",
        "body": {
          "phone": "={{ $env.OWNER_PHONE }}",
          "text": "={{ $json.alert }}"
        }
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Get Low Stock"
          }
        ]
      ]
    },
    "Get Low Stock": {
      "main": [
        [
          {
            "node": "Check Count"
          }
        ]
      ]
    },
    "Check Count": {
      "main": [
        [
          {
            "node": "Format Alert"
          }
        ]
      ]
    },
    "Format Alert": {
      "main": [
        [
          {
            "node": "Notify Owner"
          }
        ]
      ]
    }
  }
}