{
  "format": "rpai-station-workflow",
  "version": 1,
  "name": "Check contacts",
  "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 6. Validates input: reads contacts.csv and reports rows without an e-mail address instead of failing later. Put contacts.csv 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": "csv_operation",
      "name": "Read contacts",
      "properties": {
        "operation": "read",
        "filePath": "{{folder}}/contacts.csv",
        "delimiter": ",",
        "variable": "contacts"
      }
    },
    {
      "id": "academy-004",
      "type": "set_variable",
      "name": "Problems found",
      "properties": {
        "variableName": "problems",
        "valueType": "static",
        "value": "0"
      }
    },
    {
      "id": "academy-013",
      "type": "for_each_row",
      "name": "Check each contact",
      "properties": {
        "tableVariable": "contacts",
        "rowVariable": "contact",
        "indexVariable": "i"
      },
      "children": [
        {
          "id": "academy-005",
          "type": "dict_get_key",
          "name": "Name",
          "properties": {
            "dictVariable": "contact",
            "key": "Name",
            "saveToVariable": "cname"
          }
        },
        {
          "id": "academy-006",
          "type": "dict_get_key",
          "name": "Email",
          "properties": {
            "dictVariable": "contact",
            "key": "Email",
            "saveToVariable": "email"
          }
        },
        {
          "id": "academy-010",
          "type": "if",
          "name": "Email missing?",
          "properties": {
            "variable": "email",
            "operator": "is_empty",
            "value": ""
          },
          "thenBranch": [
            {
              "id": "academy-007",
              "type": "log",
              "name": "Report the problem",
              "properties": {
                "message": "Row {{i}}: {{cname}} has no e-mail address",
                "level": "warning"
              }
            },
            {
              "id": "academy-008",
              "type": "math_operation",
              "name": "Count it",
              "properties": {
                "operation": "add",
                "operand1": "problems",
                "operand2": "1",
                "saveToVariable": "problems"
              }
            },
            {
              "id": "academy-009",
              "type": "continue",
              "name": "Skip this contact",
              "properties": {}
            }
          ],
          "elseBranch": []
        },
        {
          "id": "academy-011",
          "type": "regex",
          "name": "Looks like an e-mail?",
          "properties": {
            "operation": "test",
            "input": "{{email}}",
            "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
            "saveToVariable": "ok"
          }
        },
        {
          "id": "academy-012",
          "type": "log",
          "name": "Checked",
          "properties": {
            "message": "{{cname}}: {{email}} (valid format: {{ok}})",
            "level": "info"
          }
        }
      ]
    },
    {
      "id": "academy-014",
      "type": "log",
      "name": "Summary",
      "properties": {
        "message": "{{problems}} contact(s) need attention.",
        "level": "info"
      }
    }
  ]
}
