{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://schemas.acrobits.net/core/functions/input.json",
    "$defs": {
        "button-definition": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "definition": {
                    "type": "object",
                    "properties": {
                        "interactions": {
                            "$ref": "#/$defs/interactions"
                        },
                        "location": {
                            "$ref": "#/$defs/location"
                        },
                        "style": {
                            "$ref": "#/$defs/style"
                        }
                    },
                    "required": [
                        "interactions",
                        "location",
                        "style"
                    ],
                    "additionalProperties": false
                },
                "condition": {
                    "$ref": "https://schemas.acrobits.net/core/conditions/condition.json"
                }
            },
            "required": [
                "id",
                "definition"
            ],
            "additionalProperties": false
        },
        "trigger-definition": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "definition": {
                    "oneOf": [
                        {
                            "$ref": "#/$defs/trigger-callstate"
                        },
                        {
                            "$ref": "#/$defs/trigger-group-event"
                        },
                        {
                            "$ref": "#/$defs/trigger-hold"
                        },
                        {
                            "$ref": "#/$defs/trigger-transfer"
                        },
                        {
                            "$ref": "#/$defs/trigger-reprovision"
                        }
                    ]
                },
                "condition": {
                    "$ref": "https://schemas.acrobits.net/core/conditions/condition.json"
                },
                "function": {
                    "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                }
            },
            "required": [
                "id",
                "definition",
                "function"
            ],
            "additionalProperties": false
        },
        "function-definition": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/$defs/id"
                },
                "condition": {
                    "$ref": "https://schemas.acrobits.net/core/conditions/condition.json"
                },
                "exported": {
                    "type": "boolean"
                },
                "definition": {
                    "oneOf": [
                        {
                            "$ref": "#/$defs/function-log"
                        },
                        {
                            "$ref": "#/$defs/function-setvariable"
                        },
                        {
                            "$ref": "#/$defs/function-extract-json-values"
                        },
                        {
                            "$ref": "#/$defs/function-dtmf"
                        },
                        {
                            "$ref": "#/$defs/function-httplink"
                        },
                        {
                            "$ref": "#/$defs/function-dialaction"
                        },
                        {
                            "$ref": "#/$defs/function-sendlinkupmessage"
                        },
                        {
                            "$ref": "#/$defs/function-sendlinkupsmsmessage"
                        },
                        {
                            "$ref": "#/$defs/function-createandopenlinkupchannel"
                        },
                        {
                            "$ref": "#/$defs/function-openlinkupchannel"
                        },
                        {
                            "$ref": "#/$defs/function-navigation"
                        },
                        {
                            "$ref": "#/$defs/function-webrequest"
                        },
                        {
                            "$ref": "#/$defs/function-delay"
                        },
                        {
                            "$ref": "#/$defs/function-functionsequence"
                        },
                        {
                            "$ref": "#/$defs/function-firstfunctionof"
                        },
                        {
                            "$ref": "#/$defs/function-functionsequenceuntil"
                        },
                        {
                            "$ref": "#/$defs/function-parallelfunctions"
                        },
                        {
                            "$ref": "#/$defs/function-withcallscope"
                        },
                        {
                            "$ref": "#/$defs/function-notification"
                        },
                        {
                            "$ref": "#/$defs/function-hangup"
                        },
                        {
                            "$ref": "#/$defs/function-answer"
                        },
                        {
                            "$ref": "#/$defs/function-reject"
                        },
                        {
                            "$ref": "#/$defs/function-toggle-mute"
                        },
                        {
                            "$ref": "#/$defs/function-toggle-hold"
                        },
                        {
                            "$ref": "#/$defs/function-toggle-record"
                        },
                        {
                            "$ref": "#/$defs/function-logout"
                        }
                    ]
                }
            },
            "required": [
                "id",
                "definition"
            ],
            "additionalProperties": false
        },
        "id": {
            "type": "string",
            "minLength": 2,
            "pattern": "^[a-z0-9_]+$"
        },
        "interactions": {
            "type": "object",
            "title": "Interactions for different types of gestures",
            "propertyNames": {
                "enum": [
                    "press",
                    "longPress"
                ]
            },
            "additionalProperties": {
                "$ref": "https://schemas.acrobits.net/core/requests/function.json"
            }
        },
        "location": {
            "title": "Location of the button",
            "oneOf": [
                {
                    "$ref": "#/$defs/keypad-location"
                },
                {
                    "$ref": "#/$defs/callscreen-location"
                },
                {
                    "$ref": "#/$defs/homebar-location"
                },
                {
                    "$ref": "#/$defs/account-details-location"
                }
            ]
        },
        "keypad-location": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "keypad"
                },
                "slot": {
                    "type": "string",
                    "enum": [
                        "voiceMail",
                        "call",
                        "gsmCall"
                    ]
                }
            },
            "required": [
                "@",
                "slot"
            ],
            "additionalProperties": false
        },
        "callscreen-location": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "callScreen"
                },
                "slot": {
                    "type": "string",
                    "enum": [
                        "custom1",
                        "custom2",
                        "custom3",
                        "custom4",
                        "custom5",
                        "custom6"
                    ]
                }
            },
            "required": [
                "@",
                "slot"
            ],
            "additionalProperties": false
        },
        "homebar-location": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "homeBar"
                },
                "slot": {
                    "type": "string",
                    "enum": [
                        "custom1",
                        "custom2"
                    ]
                }
            },
            "required": [
                "@",
                "slot"
            ],
            "additionalProperties": false
        },
        "account-details-location": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "accountDetails"
                },
                "slot": {
                    "type": "string",
                    "enum": [
                        "custom1",
                        "custom2",
                        "custom3",
                        "custom4",
                        "custom5"
                    ]
                }
            },
            "required": [
                "@",
                "slot"
            ],
            "additionalProperties": false
        },
        "style": {
            "$ref": "https://schemas.acrobits.net/core/styles/button.json"
        },
        "trigger-callstate": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "callState"
                },
                "state": {
                    "$ref": "https://schemas.acrobits.net/core/data/call-state.json"
                }
            },
            "required": [
                "@",
                "state"
            ],
            "additionalProperties": false
        },
        "trigger-group-event": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "groupEvent"
                },
                "event": {
                    "type": "string",
                    "enum": [
                        "groupCreated",
                        "callAdded",
                        "callRemoved",
                        "groupRemoved"
                    ]
                }
            },
            "required": [
                "@",
                "event"
            ],
            "additionalProperties": false
        },
        "trigger-hold": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "hold"
                },
                "whenHeld": {
                    "type": "boolean"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "trigger-transfer": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "transfer"
                },
                "state": {
                	"type": "string",
                    "enum": [
                        "Started",
                        "Successful",
                        "Failed"
                    ]
                }
            },
            "required": [
                "@",
                "state"
            ],
            "additionalProperties": false
        },
        "trigger-reprovision": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "reprovision"
                },
                "eventType": {
                    "enum": [
                        "AfterCompleted"
                    ]
                }
            },
            "required": [
                "@",
                "eventType"
            ],
            "additionalProperties": false
        },
        "function-log": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "log"
                },
                "message": {
                    "$ref": "https://schemas.acrobits.net/core/requests/translation.json"
                },
                "level": {
                	"type": "string",
                    "enum": [
                        "Debug",
                        "Info",
                        "Warning",
                        "Error"
                    ]
                }
            },
            "required": [
                "@",
                "message"
            ],
            "additionalProperties": false
        },
        "function-setvariable": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "setVariable"
                },
                "name": {
                    "type": "string",
                    "minLength": 1
                },
                "value": {
                    "type": "string"
                }
            },
            "required": [
                "@",
                "name",
                "value"
            ],
            "additionalProperties": false
        },
        "function-extract-json-values": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "extractJsonValues"
                },
                "value": {
                    "type": "string"
                },
                "mappings": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "minLength": 1
                            },
                            "path": {
                                "type": "string",
                                "minLength": 1
                            }
                        },
                        "required": [
                            "name",
                            "path"
                        ],
                        "additionalProperties": false
                    },
                    "minItems": 1
                }
            },
            "required": [
                "@",
                "value",
                "mappings"
            ],
            "additionalProperties": false
        },
        "function-dtmf": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "dtmf"
                },
                "dtmfSequence": {
                    "type": "string",
                    "minLength": 1
                }
            },
            "required": [
                "@",
                "dtmfSequence"
            ],
            "additionalProperties": false
        },
        "function-httplink": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "link"
                },
                "url": {
                    "type": "string",
                    "format": "uri"
                }
            },
            "required": [
                "@",
                "url"
            ],
            "additionalProperties": false
        },
        "function-dialaction": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "dialAction"
                },
                "uri": {
                    "type": "string",
                    "format": "uri"
                },
                "accountId": {
                    "type": "string"
                },
                "dialAction": {
                    "type": "string",
                    "enum": [
                        "autoCall",
                        "voiceCall",
                        "videoCall",
                        "gsmCall",
                        "webCallback",
                        "callThrough",
                        "text",
                        "openUrl",
                        "options",
                        "customOptions",
                        "forceOffnet"
                    ]
                }
            },
            "required": [
                "@",
                "uri"
            ],
            "additionalProperties": false
        },
        "function-sendlinkupmessage": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "sendLinkupMessage"
                },
                "recipient": {
                    "type": "string",
                    "minLength": 1
                },
                "message": {
                    "type": "string"
                }
            },
            "required": [
                "@",
                "recipient",
                "message"
            ],
            "additionalProperties": false
        },
        "function-sendlinkupsmsmessage": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "sendLinkupSmsMessage"
                },
                "recipient": {
                    "type": "string",
                    "minLength": 2
                },
                "message": {
                    "type": "string"
                }
            },
            "required": [
                "@",
                "recipient",
                "message"
            ],
            "additionalProperties": false
        },
        "function-createandopenlinkupchannel": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "createAndOpenLinkupChannel"
                },
                "cloudUsername": {
                    "type": "string"
                },
                "uri": {
                    "type": "string"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-openlinkupchannel": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "openLinkupChannel"
                },
                "streamId": {
                    "type": "string"
                },
                "messageId": {
                    "type": "string"
                }
            },
            "required": [
                "@",
                "streamId"
            ],
            "additionalProperties": false
        },
        "function-navigation": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "navigate"
                },
                "path": {
                    "type": "string",
                    "minLength": 1
                }
            },
            "required": [
                "@",
                "path"
            ],
            "additionalProperties": false
        },
        "function-webrequest": {
            "allOf": [
                {
                    "$ref": "https://schemas.acrobits.net/core/requests/web.json"
                },
                {
                    "properties": {
                        "@": {
                            "const": "webRequest"
                        },
                        "save": {
                            "type": "object",
                            "properties": {
                                "headers": {
                                    "type": "object",
                                    "additionalProperties": {
                                        "type": "string",
                                        "minLength": 1
                                    }
                                },
                                "body": {
                                    "type": "string",
                                    "minLength": 1
                                },
                                "statusCode": {
                                    "type": "string",
                                    "minLength": 1
                                }
                            },
                            "additionalProperties": false
                        }
                    },
                    "required": [
                        "@"
                    ]
                }
            ]
        },
        "function-delay": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "delayed"
                },
                "function": {
                    "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                },
                "hours": {
                    "type": "integer",
                    "minimum": 0
                },
                "minutes": {
                    "type": "integer",
                    "minimum": 0
                },
                "seconds": {
                    "type": "integer",
                    "minimum": 0
                },
                "milliseconds": {
                    "type": "integer",
                    "minimum": 0
                }
            },
            "required": [
                "@",
                "function"
            ],
            "additionalProperties": false
        },
        "function-functionsequence": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "functionSequence"
                },
                "sequence": {
                    "type": "array",
                    "items": {
                        "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                    },
                    "minItems": 2
                }
            },
            "required": [
                "@",
                "sequence"
            ],
            "additionalProperties": false
        },
        "function-firstfunctionof": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "firstFunctionOf"
                },
                "functions": {
                    "type": "array",
                    "items": {
                        "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                    },
                    "minItems": 2
                }
            },
            "required": [
                "@",
                "functions"
            ],
            "additionalProperties": false
        },
        "function-functionsequenceuntil": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "functionSequenceUntil"
                },
                "sequence": {
                    "type": "array",
                    "items": {
                        "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                    },
                    "minItems": 2
                }
            },
            "required": [
                "@",
                "sequence"
            ],
            "additionalProperties": false
        },
        "function-parallelfunctions": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "parallel"
                },
                "await": {
                    "type": "string",
                    "enum": [
                        "all",
                        "any"
                    ]
                },
                "functions": {
                    "type": "array",
                    "items": {
                        "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                    },
                    "minItems": 2
                }
            },
            "required": [
                "@",
                "functions"
            ],
            "additionalProperties": false
        },
        "function-withcallscope": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "withCallScope"
                },
                "function": {
                    "$ref": "https://schemas.acrobits.net/core/requests/function.json"
                },
                "callId": {
                    "type": "string",
                    "minLength": 1
                },
                "groupId": {
                    "type": "string",
                    "minLength": 1
                }
            },
            "required": [
                "@",
                "function"
            ],
            "additionalProperties": false
        },
        "function-notification": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "notification"
                },
                "definition": {
                    "$ref": "https://schemas.acrobits.net/core/requests/notification-v1.json"
                }
            },
            "required": [
                "@",
                "definition"
            ],
            "additionalProperties": false
        },
        "function-hangup": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "hangup"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-answer": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "answer"
                },
                "intent": {
                    "type": "string"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-reject": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "reject"
                },
                "mode": {
                    "$ref": "https://schemas.acrobits.net/core/data/reject-mode.json"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-toggle-mute": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "toggleMute"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-toggle-hold": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "toggleHold"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-toggle-record": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "toggleRecord"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        },
        "function-logout": {
            "type": "object",
            "properties": {
                "@": {
                    "const": "logout"
                },
                "mode": {
                    "type": "string",
                    "enum": [
                        "reset",
                        "logout"
                    ]
                },
                "attended": {
                    "type": "boolean"
                }
            },
            "required": [
                "@"
            ],
            "additionalProperties": false
        }
    },
    "type": "object",
    "properties": {
        "buttons": {
            "title": "Array of button definitions",
            "type": "array",
            "items": {
                "$ref": "#/$defs/button-definition"
            }
        },
        "triggers": {
            "title": "Array of trigger definitions",
            "type": "array",
            "items": {
                "$ref": "#/$defs/trigger-definition"
            }
        },
        "functions": {
            "title": "Array of function definitions",
            "type": "array",
            "items": {
                "$ref": "#/$defs/function-definition"
            }
        },
        "version": {
            "title": "Version of the json format",
            "type": "integer",
            "minimum": 1
        },
        "$schema": {
            "type": "string"
        }
    },
    "required": [
        "buttons",
        "triggers",
        "functions",
        "version"
    ],
    "additionalProperties": false
}
