{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "additionalProperties": false,
    "type": "object",
    "properties": {
        "resultPath": {
            "title": "Result Path",
            "description": "JSON path to store the results",
            "minLength": 1,
            "type": "string"
        },
        "deviceTags": {
            "title": "Device Tags",
            "type": "array",
            "items": {
                "title": "Device Tag Pair",
                "type": "object",
                "properties": {
                    "key": {
                        "type": "string"
                    },
                    "value": {
                        "type": "string"
                    }
                },
                "minLength": 1
            }
        },
        "deviceIds": {
            "title": "Device IDs",
            "type": "array",
            "items": {
                "title": "Device ID",
                "type": "string",
                "minLength": 1
            }
        },
        "start": {
            "title": "Start Time",
            "description": "Milliseconds since the epoch start time",
            "type": "number"
        },
        "end": {
            "title": "End Time",
            "description": "Milliseconds since the epoch end time",
            "type": "number"
        },
        "duration": {
            "title": "Duration",
            "description": "Duration of aggregation in milliseconds",
            "type": "number"
        },
        "aggregation": {
            "title": "Aggregation",
            "description": "Valid aggregation function name",
            "type": "string",
            "minLength": 1
        },
        "attributes": {
            "title": "Attributes",
            "description": "Device IDs",
            "type": "array",
            "items": {
                "title": "Device ID",
                "type": "string",
                "minLength": 1
            }
        }
    },
    "allOf": [
        {
            "required": [
                "resultPath",
                "aggregation"
            ]
        },
        {
            "oneOf": [
                {
                    "required": [
                        "start",
                        "end"
                    ]
                },
                {
                    "required": [
                        "duration"
                    ]
                }
            ]
        }
    ]
}