{
  "name": "AI Vanguard | Inventory alert",
  "nodes": [
    {
      "id": "08612d81-d1c6-478f-837a-6a0331b40cfc",
      "name": "Run sample now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "6ba6c561-3d09-44fb-926e-d49f2ec3957d",
      "name": "Run on schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        180
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      }
    },
    {
      "id": "a8d82431-4874-4536-aea4-8c345025c7d6",
      "name": "Spreadsheet ID",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        90
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e34bf6c1-7e44-4df9-be86-e0dc4cd25b14",
              "name": "spreadsheetId",
              "value": "REPLACE_WITH_YOUR_SHEET_ID",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "4bc44e83-6599-4794-9da5-2057d69c46a9",
      "name": "Read Input rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        480,
        90
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Spreadsheet ID').first().json.spreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Input"
        },
        "options": {
          "outputFormatting": {
            "values": {
              "general": "UNFORMATTED_VALUE",
              "date": "FORMATTED_STRING"
            }
          }
        }
      }
    },
    {
      "id": "0845a9a8-a581-454c-82ca-da006c85e278",
      "name": "Keep exceptions with a case key",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        720,
        90
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d19bb271-9e36-4a19-9087-6d5543107e1d",
              "leftValue": "={{ String($json['Case key'] ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "f6321080-ad14-4456-8dc4-b8679d6c745e",
              "leftValue": "={{ String($json['Exception'] ?? '').trim() }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "b550ea84-faa6-4953-b7ef-2cff59105d24",
      "name": "Normalize the case key",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        960,
        90
      ],
      "parameters": {
        "includeOtherFields": true,
        "assignments": {
          "assignments": [
            {
              "id": "0018c79b-dc74-4657-bf24-d9ecdbf55036",
              "name": "Case key",
              "value": "={{ String($json['Case key']).trim().toLowerCase() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "ed047fb8-ddb9-4ee0-8ff5-609973161f4a",
      "name": "Keep one row per case",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1200,
        90
      ],
      "parameters": {
        "operation": "removeDuplicateInputItems",
        "compare": "selectedFields",
        "fieldsToCompare": "Case key",
        "options": {}
      }
    },
    {
      "id": "e325f2be-ef6a-4a4e-b42d-bfc278b26003",
      "name": "Put exceptions in Review Queue",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        90
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Spreadsheet ID').first().json.spreadsheetId }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Review Queue"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Case key": "={{ String($json['Case key']).trim().toLowerCase() }}",
            "Exception": "={{ $json['Exception'] }}",
            "Evidence": "={{ $json['Evidence'] }}",
            "Owner": "={{ $json['Owner for review'] }}",
            "Next step": "={{ $json['Next step'] }}",
            "Last seen": "={{ $now.toISO() }}"
          },
          "matchingColumns": [
            "Case key"
          ],
          "schema": [
            {
              "id": "Case key",
              "displayName": "Case key",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Exception",
              "displayName": "Exception",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Evidence",
              "displayName": "Evidence",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Owner",
              "displayName": "Owner",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Next step",
              "displayName": "Next step",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Last seen",
              "displayName": "Last seen",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Review status",
              "displayName": "Review status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Reviewer notes",
              "displayName": "Reviewer notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW",
          "useAppend": true
        }
      }
    }
  ],
  "connections": {
    "Run sample now": {
      "main": [
        [
          {
            "node": "Spreadsheet ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run on schedule": {
      "main": [
        [
          {
            "node": "Spreadsheet ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet ID": {
      "main": [
        [
          {
            "node": "Read Input rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Input rows": {
      "main": [
        [
          {
            "node": "Keep exceptions with a case key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep exceptions with a case key": {
      "main": [
        [
          {
            "node": "Normalize the case key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize the case key": {
      "main": [
        [
          {
            "node": "Keep one row per case",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep one row per case": {
      "main": [
        [
          {
            "node": "Put exceptions in Review Queue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Amman",
    "saveManualExecutions": false
  }
}
