{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Database descriptor",
  "description": "This schema defines the properties of a BEAT database",

  "type": "object",

  "properties": {

    "root_folder": {
      "type": "string",
      "pattern": "^((file://)?(/[^/]+)+|nfs://[a-z0-9._-]+:(/[^/]+)+)$"
    },

    "protocols": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/definitions/protocol" }
    },

    "description": { "$ref": "../common/1.json#/definitions/description" },

    "schema_version": { "$ref": "../common/1.json#/definitions/version" }

  },

  "required": [
    "root_folder",
    "protocols"
  ],

  "additionalProperties": false,

  "definitions": {

    "identifier": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_-]+$"
    },

    "view": {
      "type": "string",
      "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
    },

    "protocol": {
      "type": "object",
      "properties": {
        "name": { "$ref": "#/definitions/protocol_name" },
        "template": { "$ref": "#/definitions/identifier" },
        "sets": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "$ref": "#/definitions/set" }
        }
      },
      "required": ["name", "template", "sets"],
      "additionalProperties": false
    },

    "protocol_name": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_][\\.a-zA-Z0-9_-]*$"
    },

    "set": {
      "type": "object",
      "properties": {
        "name": { "$ref": "#/definitions/identifier" },
        "template": { "$ref": "#/definitions/identifier" },
        "view": { "$ref": "#/definitions/view" },
        "parameters": { "$ref": "#/definitions/parameters" },
        "outputs": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z_][a-zA-Z0-9_-]*$": {
              "$ref": "../common/1.json#/definitions/reference"
            }
          },
          "minProperties": 1,
          "uniqueItems": true,
          "additionalProperties": false
        }
      },
      "required": ["name", "view", "outputs"],
      "additionalProperties": false
    },

    "parameters": {
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_-]*$": {
          "$ref": "#/definitions/parameter_value"
        }
      }
    },

    "parameter_value": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        }
      ]
    }

  }

}
