{
    "settings": {
        "type": "object",
        "title": "Socket.IO Settings",
        "additionalProperties": false,
        "options": {
            "disable_edit_json": true
        },
        "properties": {}
    },
    "collections": {
        "namespaces": {
            "title": "Namespace",
            "type": "object",
            "additionalProperties": false,
            "required": [
                "name",
                "settings"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "settings": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "namespace": {
                            "type": "string"
                        },
                        "url": {
                            "title": "namespace url",
                            "$ref":"#/definitions/webhooks"
                        },
                        "add_metadata": {
                            "title": "add meta data",
                            "type": "boolean",
                            "format": "checkbox",
                            "description": "Wether to add metadata to all messages and responses. All messages will be of type object. Message data will be wrapped in data property"
                        },
                        "level": {
                            "type": "string"
                        },
                        "argument": {
                            "title": "level argument",
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "name",
                                "type"
                            ],
                            "options": {
                                "disable_properties": true
                            },
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "type": {
                                    "type": "string"
                                }
                            }
                        },
                        "id_pattern": {
                            "type": "object",
                            "title": "room id pattern",
                            "default": {
                                "length": 8,
                                "characters": "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            },
                            "properties": {
                                "length": {
                                    "type": "number"
                                },
                                "characters": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "rooms": {
                    "type": "array",
                    "readOnly": true,
                    "format": "table",
                    "options": {
                        "disable_array_add": true,
                        "disable_array_delete": true,
                        "disable_array_delete_all_rows": true,
                        "disable_array_delete_last_row": true,
                        "disable_array_reorder": true
                    },
                    "items": {
                        "type": "object",
                        "additionalProperties": {
                            "readOnly": true
                        },
                        "options": {
                            "disable_edit_json": true,
                            "disable_properties": true
                        },
                        "title": "room",
                        "properties": {
                            "id": {
                                "type": "string",
                                "readOnly": true
                            },
                            "name": {
                                "type": "string",
                                "readOnly": true
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "socket_response": {
            "type": "string",
            "description": "On match, respond to the incoming message."
        }
    },
    "action_variables": {
        "onSocketioMessage": {
            "room": {
                "type": "string"
            },
            "topic": {
                "type": "string"
            },
            "match": {
            },
            "message": {
                "type": [
                    "string",
                    "number",
                    "integer",
                    "object",
                    "array"
                ]
            }
        }
    },
    "actions": {
        "sendSocketioMessage": {
            "title": "Send Socket.IO Message",
            "type": "object",
            "required": [
                "namespace",
                "topic",
                "message"
            ],
            "documentation":"https://docs.adaptorex.org/basics/actions/socketio/sendSocketioMessage.html",
            "default": {
                "room":"",
                "topic": "",
                "message": "",
                "add_metadata": false
            },
            "template": "{return { title:`socketio ${action.name}`, subtitle:`${payload.namespace} send ${payload.topic} to room ${payload.room || 'broadcast'}`, body: [{text: payload.message}]}}",
            "additionalProperties": false,
            "properties": {
                "namespace": {
                    "$ref": "#/definitions/socketio_namespaces"
                },
                "room": {
                    "type": "string"
                },
                "topic": {
                    "type": "string"
                },
                "message": {
                    "type": [
                        "string",
                        "number",
                        "boolean"
                    ],
                    "format": "textarea"
                },
                "add_metadata": {
                    "title": "add meta data",
                    "type": "boolean",
                    "format": "checkbox",
                    "description": "Include meta data like timestamp to message and wrap data in payload property."
                }
            }
        },
        "onSocketioMessage": {
            "type": "object",
            "title": "On Socket.IO Message",
            "mode": "listen",
            "documentation":"https://docs.adaptorex.org/basics/actions/socketio/onSocketioMessage.html",
            "resolveAdaptorVariables": false,
            "required": [
                "namespace",
                "topic"
            ],
            "default": {
                "room": "",
                "topic": "",
                "if": []
            },
            "additionalProperties": false,
            "properties": {
                "namespace": {
                    "$ref": "#/definitions/socketio_namespaces"
                },
                "room": {
                    "type": "string"
                },
                "topic": {
                    "type": "string",
                    "isAdaptorContent": false
                },
                "if": {
                    "type": "array",
                    "title": "if",
                    "items": {
                        "title": "condition",
                        "oneOf": [
                            {
                                "title": "Equals",
                                "description": "If message equals the or any of the following values",
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "equals"
                                ],
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "equals": {
                                        "$ref": "#/definitions/equals"
                                    },
                                    "case_sensitive": {
                                        "type": "boolean",
                                        "format": "checkbox",
                                        "title": "case sensitive"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Contains",
                                "description": "If message contains the or any of the following values",
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "contains"
                                ],
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "contains": {
                                        "$ref": "#/definitions/contains"
                                    },
                                    "case_sensitive": {
                                        "type": "boolean",
                                        "format": "checkbox",
                                        "title": "case sensitive"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Less Than",
                                "description": "If message is value that is less than",
                                "type": "object",
                                "default": {
                                    "lessThan": ""
                                },
                                "additionalProperties": false,
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "lessThan": {
                                        "$ref": "#/definitions/lessThan"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Greater Than",
                                "description": "If message is value that is greater than",
                                "type": "object",
                                "default": {
                                    "greaterThan": ""
                                },
                                "additionalProperties": false,
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "greaterThan": {
                                        "$ref": "#/definitions/greaterThan"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Regular Expression",
                                "description": "If regular expression returns anything when used on incoming message",
                                "type": "object",
                                "default": {
                                    "regex": ""
                                },
                                "additionalProperties": false,
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "regex": {
                                        "$ref": "#/definitions/regex"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Javascript function",
                                "description": "If javascript function returns true. Use value as function argument.",
                                "type": "object",
                                "default": {
                                    "javascript": ""
                                },
                                "additionalProperties": false,
                                "properties": {
                                    "field": {
                                        "$ref": "#/definitions/field"
                                    },
                                    "javascript": {
                                        "$ref": "#/definitions/javascript"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            },
                            {
                                "title": "Database Query",
                                "description": "If database find query returns a valid document. You can use event 'payload' action var in query: [[action.payload]]",
                                "type": "object",
                                "default": {
                                    "find": ""
                                },
                                "additionalProperties": false,
                                "properties": {
                                    "find": {
                                        "$ref": "#/definitions/find"
                                    },
                                    "respond": {
                                        "$ref": "#/definitions/socket_response"
                                    },
                                    "next": {
                                        "$ref": "#/definitions/next"
                                    }
                                }
                            }
                        ]
                    }
                },
                "else": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "respond": {
                            "$ref": "#/definitions/socket_response"
                        },
                        "next": {
                            "$ref": "#/definitions/next"
                        }
                    }
                },
                "priority":{
                    "type": "number",
                    "default": 1,
                    "description": "Ignore this if there is an On Socket Message action with the same members of higher priority in a different path or session. Otherwise prefer this action. If priority is the same, latest 'On Socket Message' is preferred.",
                    "enum": [
                        0,
                        1,
                        2
                    ],
                    "options": {
                        "enum_titles": [
                            "low",
                            "normal",
                            "high"
                        ]
                    }
                },
                "keep_listening": {"$ref":"#/definitions/keep_listening"}
            }
        }
    }
}