{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Templates",
    "description": "Template Definitions used to create Automation Objects.",
    "type": "array",
    "minItems": 1,
    "items": {
        "type": "object",
        "title": "Rule Template",
        "description": "Rule Template Definition",
        "additionalProperties": false,
        "required": [
            "uid",
            "triggers",
            "actions"
        ],
        "properties": {
            "uid": {
                "type": "string",
                "title": "Rule uid",
                "description": "Short (one word) user friendly description of the Rule. It must be unique."
            },
            "tags": {
                "type": "array",
                "title": "Rule Tags",
                "description": "Non-hierarchical keywords or terms describing the Rule. They help to classify the rules and allow them to be found.",
                "minItems": 1,
                "items": {
                    "type": "string"
                }
            },
            "description": {
                "type": "string",
                "title": "Rule Description",
                "description": "A brief description of what the rule is and for what it is used."
            },
            "visibility": {
                "enum": [
                    "PUBLIC",
                    "PRIVATE"
                ],
                "default": "PUBLIC"
            },
            "configDescriptions": {
                "type": "array",
                "title": "Trigger Configurations",
                "description": "Used to configure the Trigger. Contains objects describing Configuration Properties.",
                "minItems": 1,
                "items": {
                    "type": "object",
                    "title": "Configuration Property",
                    "description": "Property for configuring Rule or Module.",
                    "additionalProperties": false,
                    "required": [
                        "type",
                        "name"
                    ],
                    "properties": {
                        "name": {
                            "pattern": "[A-Za-z0-9]+",
                            "type": "string"
                        },
                        "type": {
                            "enum": [
                                "TEXT",
                                "INTEGER",
                                "DECIMAL",
                                "BOOLEAN"
                            ],
                            "title": "Configuration Parameter Type",
                            "description": "Property declaring data type of the Configuration Parameter."
                        },
                        "label": {
                            "type": "string",
                            "title": "Configuration Parameter Label",
                            "description": "A human understandable label of the Configuration Parameter."
                        },
                        "description": {
                            "type": "string",
                            "title": "Configuration Parameter Description",
                            "description": "A human understandable description of the Configuration Parameter."
                        },
                        "required": {
                            "type": "boolean",
                            "default": false,
                            "title": "Required Configuration Parameter",
                            "description": "Specifies whether the value is required."
                        },
                        "min": {
                            "type": "number",
                            "title": "Configuration Parameter Minimum Allowed Value",
                            "description": "Minimum value of numeric types, minimal length for strings, minimal number selected options."
                        },
                        "max": {
                            "type": "number",
                            "title": "Configuration Parameter Maximum Allowed Value",
                            "description": "Maximum value of numeric types, maximal length for strings, maximal number selected options."
                        },
                        "step": {
                            "type": "number",
                            "title": "Configuration Parameter Step",
                            "description": "A constant value for increasing/decreasing numeric types"
                        },
                        "pattern": {
                            "type": "string",
                            "title": "Configuration Parameter Pattern",
                            "description": "Regular script for subscribing text types."
                        },
                        "readOnly": {
                            "type": "boolean",
                            "default": false,
                            "title": "Readable Configuration Parameter",
                            "description": "Specifies whether the value is read-only."
                        },
                        "multiple": {
                            "type": "boolean",
                            "default": false,
                            "title": "Multiple Configuration Parameter",
                            "description": "Specifies whether multiple selections of options are allowed."
                        },
                        "context": {
                            "type": "string",
                            "title": "Configuration Parameter Context",
                            "description": "Serves to determine how to treat the value of the Configuration Parameter."
                        },
                        "defaultValue": {
                            "title": "Configuration Parameter Default Value",
                            "description": "Declaring a default value for the Configuration Parameter if missing."
                        },
                        "value": {
                            "title": "Configuration Parameter Value",
                            "description": "Declaring a value for the Configuration Parameter in case of system context."
                        },
                        "filterCriteria": {
                            "type": "array",
                            "title": "Configuration Parameter Filter",
                            "description": "Criteria for dynamic selection of values.",
                            "items": {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "name",
                                    "value"
                                ],
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "value": {
                                        "type": "string"
                                    }
                                }
                            }
                        },
                        "options": {
                            "type": "array",
                            "title": "Configuration Parameter Options",
                            "description": "List of definitions of the parameter for static selection.",
                            "items": {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "label",
                                    "value"
                                ],
                                "properties": {
                                    "label": {
                                        "type": "string"
                                    },
                                    "value": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "triggers": {
                "type": "array",
                "minItems": 1,
                "title": "Trigger Modules",
                "description": "Contains definitions of the Trigger Modules of the Rule.",
                "items": {
                    "type": "object",
                    "title": "Trigger Module",
                    "description": "Defines the fact which triggers the Rule execution.",
                    "additionalProperties": false,
                    "required": [
                        "id",
                        "type"
                    ],
                    "properties": {
                        "id": {
                            "type": "string",
                            "title": "Trigger uid",
                            "description": "Identifies uniquely the Module in scope of the Rule."
                        },
                        "type": {
                            "type": "string",
                            "title": "Trigger Module Type",
                            "description": "Identifies the Module Type used for creation of the Trigger Composition. Must be unique in scope of concrete Rule definition."
                        },
                        "configuration": {
                            "type": "object",
                            "title": "Trigger Configurations",
                            "description": "Used to configure the Trigger Composition. Contains pairs of Configuration Property's name and its value."
                        }
                    }
                }
            },
            "conditions": {
                "type": "array",
                "minItems": 0,
                "title": "Condition Modules",
                "description": "Contains definitions of Condition Modules of the rule.",
                "items": {
                    "type": "object",
                    "title": "Condition Module",
                    "description": "Defines the condition which permit to proceed with the Rule execution.",
                    "additionalProperties": false,
                    "required": [
                        "id",
                        "type"
                    ],
                    "properties": {
                        "id": {
                            "type": "string",
                            "title": "Condition uid",
                            "description": "Identifies uniquely the Module in scope of the Rule."
                        },
                        "type": {
                            "type": "string",
                            "title": "Condition Module Type",
                            "description": "Identifies the Module Type used for creation of the Condition. Must be unique in scope of concrete Rule definition."
                        },
                        "configuration": {
                            "type": "object",
                            "title": "Condition Configurations",
                            "description": "Used to configure the Condition. Contains pairs of Configuration Property's name and its value."
                        },
                        "inputs": {
                            "type": "object",
                            "title": "Condition Input",
                            "description": "Contains pairs of Input uid and Output reference in format - ModuleUID : OutputUID."
                        }
                    }
                }
            },
            "actions": {
                "type": "array",
                "minItems": 1,
                "title": "Action Modules",
                "description": "Contains definitions of Action Modules of the rule.",
                "items": {
                    "type": "object",
                    "title": "Action Module",
                    "description": "Defines an action which has to be executed by the Rule.",
                    "additionalProperties": false,
                    "required": [
                        "id",
                        "type"
                    ],
                    "properties": {
                        "id": {
                            "type": "string",
                            "title": "Action uid",
                            "description": "Identifies uniquely the Module in scope of the Rule."
                        },
                        "type": {
                            "type": "string",
                            "title": "Action Module Type",
                            "description": "Identifies the Module Type used for creation of the Action. Must be unique in scope of concrete Rule definition."
                        },
                        "configuration": {
                            "type": "object",
                            "title": "Action Configurations",
                            "description": "Used to configure the Action. Contains pairs of Configuration Property's name and its value."
                        },
                        "inputs": {
                            "type": "object",
                            "title": "Action Input",
                            "description": "Contains pairs of Input uid and Output reference in format - ModuleUID : OutputUID."
                        },
                        "outputs": {
                            "type": "object",
                            "title": "Action Output",
                            "description": "Contains pairs of Output uid and Output reference. The reference defines what part of a complex data has to be used as value of this output."
                        }
                    }
                }
            }
        }
    }
}