{
    "$schema": "https://schema.management.azure.com/schemas/2021-09-09/uiFormDefinition.schema.json",
    "view": {
        "kind": "Form",
        "properties": {
            "title": "OpenVidu Single Node Deployment",
            "steps": [
                {
                    "name": "basics",
                    "label": "Provide a Resource Group and a Stack Name",
                    "elements": [
                        {
                            "name": "resourceScope",
                            "type": "Microsoft.Common.ResourceScope",
                            "location": {
                                "resourceTypes": [
                                    "microsoft.storage/storageaccounts",
                                    "microsoft.resources/resourcegroups"
                                ]
                            }
                        },
                        {
                            "name": "stackName",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Stack Name",
                            "subLabel": "\nStack name",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": true,
                                "regex": "",
                                "validationMessage": "",
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters SSL",
                    "label": "Domain and SSL certificate configuration",
                    "elements": [
                        {
                            "name": "certificateType",
                            "type": "Microsoft.Common.DropDown",
                            "label": "Certificate Type",
                            "subLabel": "",
                            "defaultValue": "letsencrypt",
                            "toolTip": "[[selfsigned] Not recommended for production use. If you don't have a FQDN (DomainName parameter), you can use this option to generate a self-signed certificate.\n[owncert] Valid for production environments. If you have a FQDN (DomainName parameter) and an Elastic IP, you can use this option to use your own certificate.\n[letsencrypt] Valid for production environments. If you have a FQDN (DomainName parameter) and an Elastic IP, you can use this option to generate a Let's Encrypt certificate. If you don't have a FQDN, Let's Encrypt will use sslip.io to generate a valid certificate.\n",
                            "constraints": {
                                "required": true,
                                "allowedValues": [
                                    {
                                        "label": "selfsigned",
                                        "value": "selfsigned"
                                    },
                                    {
                                        "label": "owncert",
                                        "value": "owncert"
                                    },
                                    {
                                        "label": "letsencrypt",
                                        "value": "letsencrypt"
                                    }
                                ],
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "publicIpAddressObject",
                            "type": "Microsoft.Network.PublicIpAddressCombo",
                            "label": {
                                "publicIpAddress": "Public IP address"
                            },
                            "toolTip": {
                                "publicIpAddress": "Previously created Public IP address for the OpenVidu Deployment. Blank will generate a public IP"
                            },
                            "defaultValue": {
                                "publicIpAddressName": "defaultName"
                            },
                            "options": {
                                "hideNone": true,
                                "hideDomainNameLabel": true,
                                "hideExisting": false
                            },
                            "visible": true
                        },
                        {
                            "name": "domainName",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Domain Name",
                            "subLabel": "\nDomain name for the OpenVidu Deployment. Blank will generate default domain",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "^$|^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$",
                                "validationMessage": "Please enter a valid domain name or leave it blank to generate",
                                "validations": [
                                    {
                                        "isValid": "[if(equals(steps('parameters SSL').certificateType, 'owncert'), not(empty(steps('parameters SSL').domainName)), true)]",
                                        "message": "You need to fill this parameter because you've selected owncert certificate type."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "ownPublicCertificate",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Own Public Certificate",
                            "subLabel": "\nIf certificate type is 'owncert', this parameter will be used to specify the public certificate in base64 format",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": [
                                    {
                                        "isValid": "[if(equals(steps('parameters SSL').certificateType, 'owncert'), not(empty(steps('parameters SSL').ownPublicCertificate)), true)]",
                                        "message": "You need to fill this parameter because you've selected owncert certificate type."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "ownPrivateCertificate",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Own Private Certificate",
                            "subLabel": "\nIf certificate type is 'owncert', this parameter will be used to specify the private certificate in base64 format",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": [
                                    {
                                        "isValid": "[if(equals(steps('parameters SSL').certificateType, 'owncert'), not(empty(steps('parameters SSL').ownPrivateCertificate)), true)]",
                                        "message": "You need to fill this parameter because you've selected owncert certificate type."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters MEET",
                    "label": "OpenVidu Meet configuration",
                    "elements": [
                        {
                            "name": "initialMeetAdminPassword",
                            "type": "Microsoft.Common.PasswordBox",
                            "label": {
                                "password": "Initial Meet Admin Password (Generated if empty, can be changed later from the Meet Console)",
                                "confirmPassword": "Confirm Password"
                            },
                            "toolTip": "Initial password for the 'admin' user in OpenVidu Meet. If not provided, a random password will be generated.",
                            "constraints": {
                                "required": false,
                                "regex": "^[A-Za-z0-9_-]*$",
                                "validationMessage": "Password can only contain letters, numbers, underscores and hyphens.",
                                "validations": []
                            },
                            "options": {
                                "hideConfirmation": true
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "initialMeetApiKey",
                            "type": "Microsoft.Common.PasswordBox",
                            "label": {
                                "password": "Initial API Key for OpenVidu Meet (optional, can be set later from the Meet Console)",
                                "confirmPassword": "Confirm API Key"
                            },
                            "toolTip": "Initial API key for OpenVidu Meet. If not provided, no API key will be set and the user can set it later from Meet Console.",
                            "constraints": {
                                "required": false,
                                "regex": "^[A-Za-z0-9_-]*$",
                                "validationMessage": "API key can only contain letters, numbers, underscores and hyphens.",
                                "validations": []
                            },
                            "options": {
                                "hideConfirmation": true
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters OPENVIDU",
                    "label": "OpenVidu Single Node PRO configuration",
                    "elements": [
                        {
                            "name": "openviduLicense",
                            "type": "Microsoft.Common.PasswordBox",
                            "label": {
                                "password": "Openvidu License",
                                "confirmPassword": "Confirm password"
                            },
                            "defaultValue": "",
                            "toolTip": "Visit https://openvidu.io/account",
                            "constraints": {
                                "required": true,
                                "regex": "",
                                "validationMessage": "",
                                "validations": []
                            },
                            "options": {
                                "hideConfirmation": true
                            },
                            "visible": true
                        },
                        {
                            "name": "rtcEngine",
                            "type": "Microsoft.Common.DropDown",
                            "label": "Rtc Engine",
                            "subLabel": "RTCEngine media engine to use",
                            "defaultValue": "pion",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "allowedValues": [
                                    {
                                        "label": "pion",
                                        "value": "pion"
                                    },
                                    {
                                        "label": "mediasoup",
                                        "value": "mediasoup"
                                    }
                                ],
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters INSTANCE",
                    "label": "OpenVidu instance configuration",
                    "elements": [
                        {
                            "name": "instanceType",
                            "type": "Microsoft.Compute.SizeSelector",
                            "label": "Type of Instance",
                            "toolTip": "Specifies the azure vm size for your OpenVidu instance",
                            "recommendedSizes": [
                                "Standard_B4s",
                                "Standard_B4ms",
                                "Standard_D4ps_v5",
                                "Standard_D4pls_v5"
                            ],
                            "constraints": {
                                "allowedSizes": [],
                                "excludedSizes": []
                            },
                            "options": {
                                "hideDiskTypeFilter": false
                            },
                            "osPlatform": "Linux",
                            "visible": true
                        },
                        {
                            "name": "adminUsername",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Admin Username",
                            "subLabel": "\nUsername for the Virtual Machine.",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": true,
                                "regex": "",
                                "validationMessage": "",
                                "validations": [
                                    {
                                        "isValid": "[or(or(empty(steps('parameters INSTANCE').adminUsername),and(not(startsWith(steps('parameters INSTANCE').adminUsername,'[[')),startsWith(steps('parameters INSTANCE').adminUsername,'['),endsWith(steps('parameters INSTANCE').adminUsername,']'),greater(indexOf(steps('parameters INSTANCE').adminUsername,'('),-1),greater(indexOf(steps('parameters INSTANCE').adminUsername,')'),-1))),and(not(regex(steps('parameters INSTANCE').adminUsername,'/[\\\\/\\\"\\\"\\[\\]:|<>+=;,$ ?*@]+/')),not(endsWith(steps('parameters INSTANCE').adminUsername,'.'))),regex(steps('parameters INSTANCE').adminUsername,'^[a-zA-Z0-9-]+$'))]",
                                        "message": "User name cannot contain special characters \\/\\\"[]:|<>+=;,?*@ or end with '.', and must be between 1 and 15 characters."
                                    },
                                    {
                                        "isValid": "[or(or(empty(steps('parameters INSTANCE').adminUsername),and(not(startsWith(steps('parameters INSTANCE').adminUsername,'[[')),startsWith(steps('parameters INSTANCE').adminUsername,'['),endsWith(steps('parameters INSTANCE').adminUsername,']'),greater(indexOf(steps('parameters INSTANCE').adminUsername,'('),-1),greater(indexOf(steps('parameters INSTANCE').adminUsername,')'),-1))),equals(length(filter(parse('[\"administrator\", \"admin\", \"user\", \"user1\", \"test\", \"user2\", \"test1\", \"user3\", \"admin1\", \"1\", \"123\", \"a\", \"actuser\", \"adm\", \"admin2\", \"aspnet\", \"backup\", \"console\", \"david\", \"guest\", \"john\", \"owner\", \"root\", \"server\", \"sql\", \"support\", \"support_388945a0\", \"sys\", \"test2\", \"test3\", \"user4\", \"user5\"]'),(item) => equals(toLower(item),toLower(steps('parameters INSTANCE').adminUsername)))),0))]",
                                        "message": "The specified username is not allowed. Please choose a different value."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "adminSshKey",
                            "type": "Microsoft.Compute.CredentialsCombo",
                            "label": {
                                "authenticationType": "Authentication type",
                                "sshPublicKey": "SSH public key"
                            },
                            "toolTip": {
                                "authenticationType": "",
                                "sshPublicKey": "SSH Key for the Virtual Machine."
                            },
                            "constraints": {
                                "required": true
                            },
                            "options": {
                                "hideConfirmation": true,
                                "hidePassword": true
                            },
                            "osPlatform": "Linux",
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters STORAGE",
                    "label": "Storage Account configuration",
                    "elements": [
                        {
                            "name": "storageAccountName",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Storage Account Name",
                            "subLabel": "\nName of an existing storage account. It is essential that this parameter is filled just when you want to save recordings and still using the same container after an update. If not specified, a new storage account will be generated.",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "containerName",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Container Name",
                            "subLabel": "\nName of the bucket where OpenVidu will store the recordings, if an Storage Account Name is specified this parameter will act as the container name for the recordings that exists in the Storage Account. If not specified, a default bucket will be created.",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "FLAGS",
                    "label": "(Optional) Additional Install Flags",
                    "elements": [
                        {
                            "name": "additionalInstallFlags",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Additional Install Flags",
                            "subLabel": "Additional optional flags to pass to the OpenVidu installer (comma-separated, e.g., \"--flag1=value, --flag2\")",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "^[A-Za-z0-9, =_.\\-]*$",
                                "validationMessage": "Must be a comma-separated list of flags (for example, --flag=value, --bool-flag)",
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                },
                {
                    "name": "parameters TURN",
                    "label": "(Optional) TURN server configuration with TLS",
                    "elements": [
                        {
                            "name": "turnDomainName",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Turn Domain Name",
                            "subLabel": "\n(Optional) Domain name for the TURN server with TLS. Only needed if your users are behind restrictive firewalls",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": []
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "turnOwnPublicCertificate",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Turn Own Public Certificate",
                            "subLabel": "\n(Optional) This setting is applicable if the certificate type is set to 'owncert' and the TurnDomainName is specified. Provide in base64 format.",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": [
                                    {
                                        "isValid": "[if(and(equals(steps('parameters SSL').certificateType, 'owncert'), not(empty(steps('parameters TURN').turnDomainName))), not(empty(steps('parameters TURN').turnOwnPublicCertificate)), true)]",
                                        "message": "You need to fill this parameter because you've selected owncert certificate type and you've filled Turn Domain Name."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        },
                        {
                            "name": "turnOwnPrivateCertificate",
                            "type": "Microsoft.Common.TextBox",
                            "label": "Turn Own Private Certificate",
                            "subLabel": "\n(Optional) This setting is applicable if the certificate type is set to 'owncert' and the TurnDomainName is specified. Provide in base64 format.",
                            "defaultValue": "",
                            "toolTip": "",
                            "constraints": {
                                "required": false,
                                "regex": "",
                                "validationMessage": "",
                                "validations": [
                                    {
                                        "isValid": "[if(and(equals(steps('parameters SSL').certificateType, 'owncert'), not(empty(steps('parameters TURN').turnDomainName))), not(empty(steps('parameters TURN').turnOwnPrivateCertificate)), true)]",
                                        "message": "You need to fill this parameter because you've selected owncert certificate type and you've filled Turn Domain Name."
                                    }
                                ]
                            },
                            "infoMessages": [],
                            "visible": true
                        }
                    ]
                }
            ]
        },
        "outputs": {
            "kind": "ResourceGroup",
            "location": "[steps('basics').resourceScope.location.name]",
            "resourceGroupId": "[steps('basics').resourceScope.resourceGroup.id]",
            "parameters": {
                "stackName": "[steps('basics').stackName]",
                "certificateType": "[steps('parameters SSL').certificateType]",
                "publicIpAddressObject": "[steps('parameters SSL').publicIpAddressObject]",
                "domainName": "[steps('parameters SSL').domainName]",
                "ownPublicCertificate": "[steps('parameters SSL').ownPublicCertificate]",
                "ownPrivateCertificate": "[steps('parameters SSL').ownPrivateCertificate]",
                "openviduLicense": "[steps('parameters OPENVIDU').openviduLicense]",
                "rtcEngine": "[steps('parameters OPENVIDU').rtcEngine]",
                "turnDomainName": "[steps('parameters TURN').turnDomainName]",
                "turnOwnPublicCertificate": "[steps('parameters TURN').turnOwnPublicCertificate]",
                "turnOwnPrivateCertificate": "[steps('parameters TURN').turnOwnPrivateCertificate]",
                "initialMeetAdminPassword": "[steps('parameters MEET').initialMeetAdminPassword]",
                "initialMeetApiKey": "[steps('parameters MEET').initialMeetApiKey]",
                "instanceType": "[steps('parameters INSTANCE').instanceType]",
                "adminUsername": "[steps('parameters INSTANCE').adminUsername]",
                "adminSshKey": "[steps('parameters INSTANCE').adminSshKey]",
                "storageAccountName": "[steps('parameters STORAGE').storageAccountName]",
                "containerName": "[steps('parameters STORAGE').containerName]",
                "additionalInstallFlags": "[steps('FLAGS').additionalInstallFlags]"
            }
        }
    }
}