{
  "$id": "https://www.archivematica.org/labs/workflow/schema/v1.json",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "Archivematica Workflow JSON Schema",
  "description": "In-progress JSON Schema document for Archivematica JSON-encoded workflows.",
  "definitions": {
    "uuid": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    },
    "translations": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z]{2,3}([-_\/][a-zA-Z]{2,3})?$": {
          "type": "string"
        }
      },
      "minProperties": 1,
      "additionalProperties": false,
      "required": [
        "en"
      ]
    },
    "job_status": {
      "type": "string",
      "enum": [
        "Completed successfully",
        "Failed"
      ]
    },
    "chain": {
      "type": "object",
      "properties": {
        "link_id": {
          "$ref": "#/definitions/uuid"
        },
        "description": {
          "$ref": "#/definitions/translations"
        },
        "start": {
          "type": "boolean"
        }
      },
      "additionalProperties": false,
      "required": [
        "link_id",
        "description"
      ]
    },
    "link": {
      "type": "object",
      "properties": {
        "config": {
          "oneOf": [
            { "$ref": "#/definitions/link_model_StandardTaskFile" },
            { "$ref": "#/definitions/link_model_StandardTaskDir" },
            { "$ref": "#/definitions/link_model_ReplacementDic" },
            { "$ref": "#/definitions/link_model_ChainChoice" },
            { "$ref": "#/definitions/link_model_GetServiceOutput" },
            { "$ref": "#/definitions/link_model_GetServiceOutputPrompt" },
            { "$ref": "#/definitions/link_model_GetUnitVar" },
            { "$ref": "#/definitions/link_model_SetUnitVar" }
          ]
        },
        "exit_codes": {
          "type": "object",
          "minProperties": 0,
          "additionalProperties": {
            "type": "object",
            "properties": {
              "job_status": {
                "oneOf": [
                  { "$ref": "#/definitions/job_status" },
                  { "type": "null" }
                ]
              },
              "link_id": {
                "oneOf": [
                  { "$ref": "#/definitions/uuid" },
                  { "type": "null" }
                ]
              }
            }
          }
        },
        "fallback_job_status": {
          "oneOf": [
            { "$ref": "#/definitions/job_status" },
            { "type": "null" }
          ]
        },
        "fallback_link_id": {
          "oneOf": [
            { "$ref": "#/definitions/uuid" },
            { "type": "null" }
          ]
        },
        "description": {
          "$ref": "#/definitions/translations"
        },
        "group": {
          "$ref": "#/definitions/translations"
        },
        "end": {
          "type": "boolean"
        }
      },
      "additionalProperties": false,
      "required": [
        "config",
        "exit_codes",
        "fallback_job_status",
        "fallback_link_id",
        "description",
        "group"
      ]
    },
    "watched_dir": {
      "type": "object",
      "properties": {
        "chain_id": {
          "$ref": "#/definitions/uuid"
        },
        "only_dirs": {
          "type": "boolean"
        },
        "path": {
          "type": "string"
        },
        "unit_type": {
          "type": "string",
          "enum": [
            "Transfer",
            "DIP",
            "SIP"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "chain_id",
        "only_dirs",
        "path",
        "unit_type"
      ]
    },
    "link_model_StandardTaskFile": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerFiles"},
        "@model": {"type": "string", "pattern": "StandardTaskConfig"},
        "execute": {
          "type": "string"
        },
        "arguments": {
          "type": ["string", "null"]
        },
        "filter_file_start": {
          "type": ["string", "null"]
        },
        "filter_file_end": {
          "type": ["string", "null"]
        },
        "filter_subdir": {
          "type": ["string", "null"]
        },
        "stdout_file": {
          "type": ["string", "null"]
        },
        "stderr_file": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "execute",
        "arguments",
        "filter_file_start",
        "filter_file_end",
        "filter_subdir",
        "stdout_file",
        "stderr_file"
      ]
    },
    "link_model_StandardTaskDir": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerDirectories"},
        "@model": {"type": "string", "pattern": "StandardTaskConfig"},
        "execute": {
          "type": "string"
        },
        "arguments": {
          "type": ["string", "null"]
        },
        "filter_file_start": {
          "type": ["string", "null"]
        },
        "filter_file_end": {
          "type": ["string", "null"]
        },
        "filter_subdir": {
          "type": ["string", "null"]
        },
        "stdout_file": {
          "type": ["string", "null"]
        },
        "stderr_file": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "execute",
        "arguments",
        "filter_file_start",
        "filter_file_end",
        "filter_subdir",
        "stdout_file",
        "stderr_file"
      ]
    },
    "link_model_ReplacementDic": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerReplacementDicFromChoice"},
        "@model": {"type": "string", "pattern": "MicroServiceChoiceReplacementDic"},
        "replacements": {
          "type": "array",
          "minItems": 0,
          "items": [
            {
              "type": "object",
              "properties": {
                "id": { "$ref": "#/definitions/uuid" },
                "description": { "$ref": "#/definitions/translations" },
                "items": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              },
              "additionalProperties": false,
              "required": [
                "id",
                "description",
                "items"
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "replacements"
      ]
    },
    "link_model_ChainChoice": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerChoice"},
        "@model": {"type": "string", "pattern": "MicroServiceChainChoice"},
        "chain_choices": {
          "type": "array",
          "minItems": 1,
          "items": [
            {"$ref": "#/definitions/uuid"}
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "chain_choices"
      ]
    },
    "link_model_GetServiceOutput": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerGetMicroserviceGeneratedListInStdOut"},
        "@model": {"type": "string", "pattern": "StandardTaskConfig"},
        "execute": {
          "type": "string"
        },
        "arguments": {
          "type": ["string", "null"]
        },
        "filter_file_start": {
          "type": ["string", "null"]
        },
        "filter_file_end": {
          "type": ["string", "null"]
        },
        "filter_subdir": {
          "type": ["string", "null"]
        },
        "stdout_file": {
          "type": ["string", "null"]
        },
        "stderr_file": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "execute",
        "arguments",
        "filter_file_start",
        "filter_file_end",
        "filter_subdir",
        "stdout_file",
        "stderr_file"
      ]
    },
    "link_model_GetServiceOutputPrompt": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerGetUserChoiceFromMicroserviceGeneratedList"},
        "@model": {"type": "string", "pattern": "StandardTaskConfig"},
        "execute": {
          "type": "string"
        },
        "arguments": {
          "type": ["string", "null"]
        },
        "filter_file_start": {
          "type": ["string", "null"]
        },
        "filter_file_end": {
          "type": ["string", "null"]
        },
        "filter_subdir": {
          "type": ["string", "null"]
        },
        "stdout_file": {
          "type": ["string", "null"]
        },
        "stderr_file": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "execute",
        "arguments",
        "filter_file_start",
        "filter_file_end",
        "filter_subdir",
        "stdout_file",
        "stderr_file"
      ]
    },
    "link_model_GetUnitVar": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerUnitVariableLinkPull"},
        "@model": {"type": "string", "pattern": "TaskConfigUnitVariableLinkPull"},
        "chain_id": {
          "oneOf": [
            { "$ref": "#/definitions/uuid" },
            { "type": "null" }
          ]
        },
        "variable": {
         "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "chain_id",
        "variable"
      ]
    },
    "link_model_SetUnitVar": {
      "type": "object",
      "properties": {
        "@manager": {"type": "string", "pattern": "linkTaskManagerSetUnitVariable"},
        "@model": {"type": "string", "pattern": "TaskConfigSetUnitVariable"},
        "chain_id": {
          "oneOf": [
            { "$ref": "#/definitions/uuid" },
            { "type": "null" }
          ]
        },
        "variable": {
         "type": "string"
        },
        "variable_value": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false,
      "required": [
        "@manager",
        "@model",
        "chain_id",
        "variable",
        "variable_value"
      ]
    }
  },
  "type": "object",
  "properties": {
    "chains": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/chain"
      }
    },
    "links": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/link"
      }
    },
    "watched_directories": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/watched_dir"
      }
    }
  },
  "required": [
    "chains",
    "links",
    "watched_directories"
  ],
  "additionalProperties": false
}
