{
  "format": "rpai-station-workflow",
  "version": 1,
  "name": "JSON products",
  "variables": [
    {
      "id": "var-folder",
      "name": "folder",
      "type": "string",
      "value": "~/Documents/Station Academy"
    }
  ],
  "activities": [
    {
      "id": "academy-001",
      "type": "comment",
      "name": "About this workflow",
      "properties": {
        "text": "Station Academy, Level 4. Reads products.json, picks values with a JSON path and checks stock. Put products.json into the practice folder first."
      }
    },
    {
      "id": "academy-002",
      "type": "file_operation",
      "name": "Make sure the practice folder exists",
      "properties": {
        "operation": "create_folder",
        "sourcePath": "{{folder}}"
      }
    },
    {
      "id": "academy-003",
      "type": "json_operation",
      "name": "Read the products",
      "properties": {
        "operation": "read",
        "filePath": "{{folder}}/products.json",
        "variable": "products"
      }
    },
    {
      "id": "academy-004",
      "type": "parse_data",
      "name": "When was it updated?",
      "properties": {
        "format": "json",
        "sourceVariable": "products",
        "query": "$.updated",
        "saveToVariable": "updated"
      }
    },
    {
      "id": "academy-005",
      "type": "parse_data",
      "name": "The list of items",
      "properties": {
        "format": "json",
        "sourceVariable": "products",
        "query": "$.items",
        "saveToVariable": "items"
      }
    },
    {
      "id": "academy-011",
      "type": "loop",
      "name": "For each product",
      "properties": {
        "loopType": "collection",
        "collection": "items",
        "itemVariable": "item"
      },
      "children": [
        {
          "id": "academy-006",
          "type": "dict_get_key",
          "name": "Name",
          "properties": {
            "dictVariable": "item",
            "key": "name",
            "saveToVariable": "pname"
          }
        },
        {
          "id": "academy-007",
          "type": "dict_get_key",
          "name": "Stock",
          "properties": {
            "dictVariable": "item",
            "key": "stock",
            "saveToVariable": "stock"
          }
        },
        {
          "id": "academy-010",
          "type": "if",
          "name": "Out of stock?",
          "properties": {
            "variable": "stock",
            "operator": "equals",
            "value": "0"
          },
          "thenBranch": [
            {
              "id": "academy-008",
              "type": "log",
              "name": "Warn",
              "properties": {
                "message": "{{pname}} is out of stock",
                "level": "warning"
              }
            }
          ],
          "elseBranch": [
            {
              "id": "academy-009",
              "type": "log",
              "name": "Fine",
              "properties": {
                "message": "{{pname}}: {{stock}} in stock",
                "level": "info"
              }
            }
          ]
        }
      ]
    },
    {
      "id": "academy-012",
      "type": "log",
      "name": "Done",
      "properties": {
        "message": "Checked the product list from {{updated}}.",
        "level": "info"
      }
    }
  ]
}
