# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
    "network network-watcher connection-monitor create",
)
class Create(AAZCommand):
    """Create a connection monitor.

    :example: Create connection monitor
        az network network-watcher connection-monitor create --name cm12 --network-watcher-name networkwatcher_eastus --resource-group networkwatcherrg --location eastus --endpoints "[{name:vmName,type:AzureVM,resourceId:/subscriptions/subid/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/TESTVM-LINUX},{address:8.8.8.8,name:google,type:ExternalAddress}]" --test-configurations "[{name:TestConfiguration04,protocol:Tcp,successThreshold:{},tcpConfiguration:{disableTraceRoute:false,port:53},testFrequencySec:30}]" --test-groups "[{destinations:[google],disable:false,name:TestingGroup04,sources:[vmName],testConfigurations:[TestConfiguration04]}]"

    :example: Create Connection Monitor
        az network network-watcher connection-monitor create --name cm12 --network-watcher-name networkwatcher_eastus --resource-group networkwatcherrg --location eastus --endpoints "[{name:vmName,type:AzureVM,resourceId:/subscriptions/subid/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/TESTVM-LINUX},{address:8.8.8.8,name:google,type:ExternalAddress}]" --test-configurations "[{name:TestConfiguration04,protocol:Tcp,successThreshold:{},tcpConfiguration:{disableTraceRoute:false,port:53},testFrequencySec:30}]" --test-groups "[{destinations:[google],disable:false,name:TestingGroup04,sources:[vmName],testConfigurations:[TestConfiguration04]}]" --outputs "[{type:Workspace,workspaceSettings:{workspaceResourceId:/subscriptions/subid/resourceGroups/DefaultResourceGroup-EUS/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-sub-id-region}}]"
    """

    _aaz_info = {
        "version": "2023-09-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/networkwatchers/{}/connectionmonitors/{}", "2023-09-01"],
        ]
    }

    AZ_SUPPORT_NO_WAIT = True

    def _handler(self, command_args):
        super()._handler(command_args)
        return self.build_lro_poller(self._execute_operations, self._output)

    _args_schema = None

    @classmethod
    def _build_arguments_schema(cls, *args, **kwargs):
        if cls._args_schema is not None:
            return cls._args_schema
        cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

        # define Arg Group ""

        _args_schema = cls._args_schema
        _args_schema.connection_monitor_name = AAZStrArg(
            options=["-n", "--name", "--connection-monitor-name"],
            help="The name of the connection monitor.",
            required=True,
        )
        _args_schema.network_watcher_name = AAZStrArg(
            options=["--network-watcher-name"],
            help="The name of the Network Watcher resource.",
            required=True,
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.migrate = AAZStrArg(
            options=["--migrate"],
            help="Value indicating whether connection monitor V1 should be migrated to V2 format.",
        )

        # define Arg Group "Parameters"

        _args_schema = cls._args_schema
        _args_schema.location = AAZStrArg(
            options=["--location"],
            arg_group="Parameters",
            help="Connection monitor location.",
        )
        _args_schema.tags = AAZDictArg(
            options=["--tags"],
            arg_group="Parameters",
            help="Connection monitor tags.",
        )

        tags = cls._args_schema.tags
        tags.Element = AAZStrArg()

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.auto_start = AAZBoolArg(
            options=["--auto-start"],
            arg_group="Properties",
            help="Determines if the connection monitor will start automatically once created.",
        )
        _args_schema.endpoints = AAZListArg(
            options=["--endpoints"],
            arg_group="Properties",
            help="List of connection monitor endpoints.",
        )
        _args_schema.notes = AAZStrArg(
            options=["--notes"],
            arg_group="Properties",
            help="Optional notes to be associated with the connection monitor.",
        )
        _args_schema.outputs = AAZListArg(
            options=["--outputs"],
            arg_group="Properties",
            help="List of connection monitor outputs.",
        )
        _args_schema.test_configurations = AAZListArg(
            options=["--test-configurations"],
            arg_group="Properties",
            help="List of connection monitor test configurations.",
        )
        _args_schema.test_groups = AAZListArg(
            options=["--test-groups"],
            arg_group="Properties",
            help="List of connection monitor test groups.",
        )

        endpoints = cls._args_schema.endpoints
        endpoints.Element = AAZObjectArg()

        _element = cls._args_schema.endpoints.Element
        _element.address = AAZStrArg(
            options=["address"],
            help="Address of the connection monitor endpoint (IP or domain name).",
        )
        _element.coverage_level = AAZStrArg(
            options=["coverage-level"],
            help="Test coverage for the endpoint.",
            enum={"AboveAverage": "AboveAverage", "Average": "Average", "BelowAverage": "BelowAverage", "Default": "Default", "Full": "Full", "Low": "Low"},
        )
        _element.filter = AAZObjectArg(
            options=["filter"],
            help="Filter for sub-items within the endpoint.",
        )
        _element.name = AAZStrArg(
            options=["name"],
            help="The name of the connection monitor endpoint.",
            required=True,
        )
        _element.resource_id = AAZStrArg(
            options=["resource-id"],
            help="Resource ID of the connection monitor endpoint.",
        )
        _element.scope = AAZObjectArg(
            options=["scope"],
            help="Endpoint scope.",
        )
        _element.type = AAZStrArg(
            options=["type"],
            help="The endpoint type.",
            enum={"AzureArcVM": "AzureArcVM", "AzureSubnet": "AzureSubnet", "AzureVM": "AzureVM", "AzureVMSS": "AzureVMSS", "AzureVNet": "AzureVNet", "ExternalAddress": "ExternalAddress", "MMAWorkspaceMachine": "MMAWorkspaceMachine", "MMAWorkspaceNetwork": "MMAWorkspaceNetwork"},
        )

        filter = cls._args_schema.endpoints.Element.filter
        filter.items = AAZListArg(
            options=["items"],
            help="List of items in the filter.",
        )
        filter.type = AAZStrArg(
            options=["type"],
            help="The behavior of the endpoint filter. Currently only 'Include' is supported.",
            enum={"Include": "Include"},
        )

        items = cls._args_schema.endpoints.Element.filter.items
        items.Element = AAZObjectArg()

        _element = cls._args_schema.endpoints.Element.filter.items.Element
        _element.address = AAZStrArg(
            options=["address"],
            help="The address of the filter item.",
        )
        _element.type = AAZStrArg(
            options=["type"],
            help="The type of item included in the filter. Currently only 'AgentAddress' is supported.",
            enum={"AgentAddress": "AgentAddress"},
        )

        scope = cls._args_schema.endpoints.Element.scope
        scope.exclude = AAZListArg(
            options=["exclude"],
            help="List of items which needs to be excluded from the endpoint scope.",
        )
        scope.include = AAZListArg(
            options=["include"],
            help="List of items which needs to be included to the endpoint scope.",
        )

        exclude = cls._args_schema.endpoints.Element.scope.exclude
        exclude.Element = AAZObjectArg()
        cls._build_args_connection_monitor_endpoint_scope_item_create(exclude.Element)

        include = cls._args_schema.endpoints.Element.scope.include
        include.Element = AAZObjectArg()
        cls._build_args_connection_monitor_endpoint_scope_item_create(include.Element)

        outputs = cls._args_schema.outputs
        outputs.Element = AAZObjectArg()

        _element = cls._args_schema.outputs.Element
        _element.type = AAZStrArg(
            options=["type"],
            help="Connection monitor output destination type. Currently, only \"Workspace\" is supported.",
            enum={"Workspace": "Workspace"},
        )
        _element.workspace_settings = AAZObjectArg(
            options=["workspace-settings"],
            help="Describes the settings for producing output into a log analytics workspace.",
        )

        workspace_settings = cls._args_schema.outputs.Element.workspace_settings
        workspace_settings.workspace_resource_id = AAZStrArg(
            options=["workspace-resource-id"],
            help="Log analytics workspace resource ID.",
        )

        test_configurations = cls._args_schema.test_configurations
        test_configurations.Element = AAZObjectArg()

        _element = cls._args_schema.test_configurations.Element
        _element.http_configuration = AAZObjectArg(
            options=["http-configuration"],
            help="The parameters used to perform test evaluation over HTTP.",
        )
        _element.icmp_configuration = AAZObjectArg(
            options=["icmp-configuration"],
            help="The parameters used to perform test evaluation over ICMP.",
        )
        _element.name = AAZStrArg(
            options=["name"],
            help="The name of the connection monitor test configuration.",
            required=True,
        )
        _element.preferred_ip_version = AAZStrArg(
            options=["preferred-ip-version"],
            help="The preferred IP version to use in test evaluation. The connection monitor may choose to use a different version depending on other parameters.",
            enum={"IPv4": "IPv4", "IPv6": "IPv6"},
        )
        _element.protocol = AAZStrArg(
            options=["protocol"],
            help="The protocol to use in test evaluation.",
            required=True,
            enum={"Http": "Http", "Icmp": "Icmp", "Tcp": "Tcp"},
        )
        _element.success_threshold = AAZObjectArg(
            options=["success-threshold"],
            help="The threshold for declaring a test successful.",
        )
        _element.tcp_configuration = AAZObjectArg(
            options=["tcp-configuration"],
            help="The parameters used to perform test evaluation over TCP.",
        )
        _element.test_frequency_sec = AAZIntArg(
            options=["test-frequency-sec"],
            help="The frequency of test evaluation, in seconds.",
        )

        http_configuration = cls._args_schema.test_configurations.Element.http_configuration
        http_configuration.method = AAZStrArg(
            options=["method"],
            help="The HTTP method to use.",
            enum={"Get": "Get", "Post": "Post"},
        )
        http_configuration.path = AAZStrArg(
            options=["path"],
            help="The path component of the URI. For instance, \"/dir1/dir2\".",
        )
        http_configuration.port = AAZIntArg(
            options=["port"],
            help="The port to connect to.",
            fmt=AAZIntArgFormat(
                maximum=65535,
                minimum=0,
            ),
        )
        http_configuration.prefer_https = AAZBoolArg(
            options=["prefer-https"],
            help="Value indicating whether HTTPS is preferred over HTTP in cases where the choice is not explicit.",
        )
        http_configuration.request_headers = AAZListArg(
            options=["request-headers"],
            help="The HTTP headers to transmit with the request.",
        )
        http_configuration.valid_status_code_ranges = AAZListArg(
            options=["valid-status-code-ranges"],
            help="HTTP status codes to consider successful. For instance, \"2xx,301-304,418\".",
        )

        request_headers = cls._args_schema.test_configurations.Element.http_configuration.request_headers
        request_headers.Element = AAZObjectArg()

        _element = cls._args_schema.test_configurations.Element.http_configuration.request_headers.Element
        _element.name = AAZStrArg(
            options=["name"],
            help="The name in HTTP header.",
        )
        _element.value = AAZStrArg(
            options=["value"],
            help="The value in HTTP header.",
        )

        valid_status_code_ranges = cls._args_schema.test_configurations.Element.http_configuration.valid_status_code_ranges
        valid_status_code_ranges.Element = AAZStrArg()

        icmp_configuration = cls._args_schema.test_configurations.Element.icmp_configuration
        icmp_configuration.disable_trace_route = AAZBoolArg(
            options=["disable-trace-route"],
            help="Value indicating whether path evaluation with trace route should be disabled.",
        )

        success_threshold = cls._args_schema.test_configurations.Element.success_threshold
        success_threshold.checks_failed_percent = AAZIntArg(
            options=["checks-failed-percent"],
            help="The maximum percentage of failed checks permitted for a test to evaluate as successful.",
        )
        success_threshold.round_trip_time_ms = AAZFloatArg(
            options=["round-trip-time-ms"],
            help="The maximum round-trip time in milliseconds permitted for a test to evaluate as successful.",
        )

        tcp_configuration = cls._args_schema.test_configurations.Element.tcp_configuration
        tcp_configuration.destination_port_behavior = AAZStrArg(
            options=["destination-port-behavior"],
            help="Destination port behavior.",
            enum={"ListenIfAvailable": "ListenIfAvailable", "None": "None"},
        )
        tcp_configuration.disable_trace_route = AAZBoolArg(
            options=["disable-trace-route"],
            help="Value indicating whether path evaluation with trace route should be disabled.",
        )
        tcp_configuration.port = AAZIntArg(
            options=["port"],
            help="The port to connect to.",
            fmt=AAZIntArgFormat(
                maximum=65535,
                minimum=0,
            ),
        )

        test_groups = cls._args_schema.test_groups
        test_groups.Element = AAZObjectArg()

        _element = cls._args_schema.test_groups.Element
        _element.destinations = AAZListArg(
            options=["destinations"],
            help="List of destination endpoint names.",
            required=True,
        )
        _element.disable = AAZBoolArg(
            options=["disable"],
            help="Value indicating whether test group is disabled.",
        )
        _element.name = AAZStrArg(
            options=["name"],
            help="The name of the connection monitor test group.",
            required=True,
        )
        _element.sources = AAZListArg(
            options=["sources"],
            help="List of source endpoint names.",
            required=True,
        )
        _element.test_configurations = AAZListArg(
            options=["test-configurations"],
            help="List of test configuration names.",
            required=True,
        )

        destinations = cls._args_schema.test_groups.Element.destinations
        destinations.Element = AAZStrArg()

        sources = cls._args_schema.test_groups.Element.sources
        sources.Element = AAZStrArg()

        test_configurations = cls._args_schema.test_groups.Element.test_configurations
        test_configurations.Element = AAZStrArg()
        return cls._args_schema

    _args_connection_monitor_endpoint_scope_item_create = None

    @classmethod
    def _build_args_connection_monitor_endpoint_scope_item_create(cls, _schema):
        if cls._args_connection_monitor_endpoint_scope_item_create is not None:
            _schema.address = cls._args_connection_monitor_endpoint_scope_item_create.address
            return

        cls._args_connection_monitor_endpoint_scope_item_create = AAZObjectArg()

        connection_monitor_endpoint_scope_item_create = cls._args_connection_monitor_endpoint_scope_item_create
        connection_monitor_endpoint_scope_item_create.address = AAZStrArg(
            options=["address"],
            help="The address of the endpoint item. Supported types are IPv4/IPv6 subnet mask or IPv4/IPv6 IP address.",
        )

        _schema.address = cls._args_connection_monitor_endpoint_scope_item_create.address

    def _execute_operations(self):
        self.pre_operations()
        yield self.ConnectionMonitorsCreateOrUpdate(ctx=self.ctx)()
        self.post_operations()

    @register_callback
    def pre_operations(self):
        pass

    @register_callback
    def post_operations(self):
        pass

    def _output(self, *args, **kwargs):
        result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
        return result

    class ConnectionMonitorsCreateOrUpdate(AAZHttpOperation):
        CLIENT_TYPE = "MgmtClient"

        def __call__(self, *args, **kwargs):
            request = self.make_request()
            session = self.client.send_request(request=request, stream=False, **kwargs)
            if session.http_response.status_code in [202]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200_201,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )
            if session.http_response.status_code in [200, 201]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200_201,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}",
                **self.url_parameters
            )

        @property
        def method(self):
            return "PUT"

        @property
        def error_format(self):
            return "ODataV4Format"

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "connectionMonitorName", self.ctx.args.connection_monitor_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "networkWatcherName", self.ctx.args.network_watcher_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "subscriptionId", self.ctx.subscription_id,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "migrate", self.ctx.args.migrate,
                ),
                **self.serialize_query_param(
                    "api-version", "2023-09-01",
                    required=True,
                ),
            }
            return parameters

        @property
        def header_parameters(self):
            parameters = {
                **self.serialize_header_param(
                    "Content-Type", "application/json",
                ),
                **self.serialize_header_param(
                    "Accept", "application/json",
                ),
            }
            return parameters

        @property
        def content(self):
            _content_value, _builder = self.new_content_builder(
                self.ctx.args,
                typ=AAZObjectType,
                typ_kwargs={"flags": {"required": True, "client_flatten": True}}
            )
            _builder.set_prop("location", AAZStrType, ".location")
            _builder.set_prop("properties", AAZObjectType, ".", typ_kwargs={"flags": {"required": True, "client_flatten": True}})
            _builder.set_prop("tags", AAZDictType, ".tags")

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("autoStart", AAZBoolType, ".auto_start")
                properties.set_prop("endpoints", AAZListType, ".endpoints")
                properties.set_prop("notes", AAZStrType, ".notes")
                properties.set_prop("outputs", AAZListType, ".outputs")
                properties.set_prop("testConfigurations", AAZListType, ".test_configurations")
                properties.set_prop("testGroups", AAZListType, ".test_groups")

            endpoints = _builder.get(".properties.endpoints")
            if endpoints is not None:
                endpoints.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.endpoints[]")
            if _elements is not None:
                _elements.set_prop("address", AAZStrType, ".address")
                _elements.set_prop("coverageLevel", AAZStrType, ".coverage_level")
                _elements.set_prop("filter", AAZObjectType, ".filter")
                _elements.set_prop("name", AAZStrType, ".name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("resourceId", AAZStrType, ".resource_id")
                _elements.set_prop("scope", AAZObjectType, ".scope")
                _elements.set_prop("type", AAZStrType, ".type")

            filter = _builder.get(".properties.endpoints[].filter")
            if filter is not None:
                filter.set_prop("items", AAZListType, ".items")
                filter.set_prop("type", AAZStrType, ".type")

            items = _builder.get(".properties.endpoints[].filter.items")
            if items is not None:
                items.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.endpoints[].filter.items[]")
            if _elements is not None:
                _elements.set_prop("address", AAZStrType, ".address")
                _elements.set_prop("type", AAZStrType, ".type")

            scope = _builder.get(".properties.endpoints[].scope")
            if scope is not None:
                scope.set_prop("exclude", AAZListType, ".exclude")
                scope.set_prop("include", AAZListType, ".include")

            exclude = _builder.get(".properties.endpoints[].scope.exclude")
            if exclude is not None:
                _CreateHelper._build_schema_connection_monitor_endpoint_scope_item_create(exclude.set_elements(AAZObjectType, "."))

            include = _builder.get(".properties.endpoints[].scope.include")
            if include is not None:
                _CreateHelper._build_schema_connection_monitor_endpoint_scope_item_create(include.set_elements(AAZObjectType, "."))

            outputs = _builder.get(".properties.outputs")
            if outputs is not None:
                outputs.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.outputs[]")
            if _elements is not None:
                _elements.set_prop("type", AAZStrType, ".type")
                _elements.set_prop("workspaceSettings", AAZObjectType, ".workspace_settings")

            workspace_settings = _builder.get(".properties.outputs[].workspaceSettings")
            if workspace_settings is not None:
                workspace_settings.set_prop("workspaceResourceId", AAZStrType, ".workspace_resource_id")

            test_configurations = _builder.get(".properties.testConfigurations")
            if test_configurations is not None:
                test_configurations.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.testConfigurations[]")
            if _elements is not None:
                _elements.set_prop("httpConfiguration", AAZObjectType, ".http_configuration")
                _elements.set_prop("icmpConfiguration", AAZObjectType, ".icmp_configuration")
                _elements.set_prop("name", AAZStrType, ".name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("preferredIPVersion", AAZStrType, ".preferred_ip_version")
                _elements.set_prop("protocol", AAZStrType, ".protocol", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("successThreshold", AAZObjectType, ".success_threshold")
                _elements.set_prop("tcpConfiguration", AAZObjectType, ".tcp_configuration")
                _elements.set_prop("testFrequencySec", AAZIntType, ".test_frequency_sec")

            http_configuration = _builder.get(".properties.testConfigurations[].httpConfiguration")
            if http_configuration is not None:
                http_configuration.set_prop("method", AAZStrType, ".method")
                http_configuration.set_prop("path", AAZStrType, ".path")
                http_configuration.set_prop("port", AAZIntType, ".port")
                http_configuration.set_prop("preferHTTPS", AAZBoolType, ".prefer_https")
                http_configuration.set_prop("requestHeaders", AAZListType, ".request_headers")
                http_configuration.set_prop("validStatusCodeRanges", AAZListType, ".valid_status_code_ranges")

            request_headers = _builder.get(".properties.testConfigurations[].httpConfiguration.requestHeaders")
            if request_headers is not None:
                request_headers.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.testConfigurations[].httpConfiguration.requestHeaders[]")
            if _elements is not None:
                _elements.set_prop("name", AAZStrType, ".name")
                _elements.set_prop("value", AAZStrType, ".value")

            valid_status_code_ranges = _builder.get(".properties.testConfigurations[].httpConfiguration.validStatusCodeRanges")
            if valid_status_code_ranges is not None:
                valid_status_code_ranges.set_elements(AAZStrType, ".")

            icmp_configuration = _builder.get(".properties.testConfigurations[].icmpConfiguration")
            if icmp_configuration is not None:
                icmp_configuration.set_prop("disableTraceRoute", AAZBoolType, ".disable_trace_route")

            success_threshold = _builder.get(".properties.testConfigurations[].successThreshold")
            if success_threshold is not None:
                success_threshold.set_prop("checksFailedPercent", AAZIntType, ".checks_failed_percent")
                success_threshold.set_prop("roundTripTimeMs", AAZFloatType, ".round_trip_time_ms")

            tcp_configuration = _builder.get(".properties.testConfigurations[].tcpConfiguration")
            if tcp_configuration is not None:
                tcp_configuration.set_prop("destinationPortBehavior", AAZStrType, ".destination_port_behavior")
                tcp_configuration.set_prop("disableTraceRoute", AAZBoolType, ".disable_trace_route")
                tcp_configuration.set_prop("port", AAZIntType, ".port")

            test_groups = _builder.get(".properties.testGroups")
            if test_groups is not None:
                test_groups.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.testGroups[]")
            if _elements is not None:
                _elements.set_prop("destinations", AAZListType, ".destinations", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("disable", AAZBoolType, ".disable")
                _elements.set_prop("name", AAZStrType, ".name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("sources", AAZListType, ".sources", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("testConfigurations", AAZListType, ".test_configurations", typ_kwargs={"flags": {"required": True}})

            destinations = _builder.get(".properties.testGroups[].destinations")
            if destinations is not None:
                destinations.set_elements(AAZStrType, ".")

            sources = _builder.get(".properties.testGroups[].sources")
            if sources is not None:
                sources.set_elements(AAZStrType, ".")

            test_configurations = _builder.get(".properties.testGroups[].testConfigurations")
            if test_configurations is not None:
                test_configurations.set_elements(AAZStrType, ".")

            tags = _builder.get(".tags")
            if tags is not None:
                tags.set_elements(AAZStrType, ".")

            return self.serialize_content(_content_value)

        def on_200_201(self, session):
            data = self.deserialize_http_content(session)
            self.ctx.set_var(
                "instance",
                data,
                schema_builder=self._build_schema_on_200_201
            )

        _schema_on_200_201 = None

        @classmethod
        def _build_schema_on_200_201(cls):
            if cls._schema_on_200_201 is not None:
                return cls._schema_on_200_201

            cls._schema_on_200_201 = AAZObjectType()

            _schema_on_200_201 = cls._schema_on_200_201
            _schema_on_200_201.etag = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.location = AAZStrType()
            _schema_on_200_201.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.properties = AAZObjectType(
                flags={"client_flatten": True},
            )
            _schema_on_200_201.tags = AAZDictType()
            _schema_on_200_201.type = AAZStrType(
                flags={"read_only": True},
            )

            properties = cls._schema_on_200_201.properties
            properties.auto_start = AAZBoolType(
                serialized_name="autoStart",
            )
            properties.connection_monitor_type = AAZStrType(
                serialized_name="connectionMonitorType",
                flags={"read_only": True},
            )
            properties.destination = AAZObjectType()
            properties.endpoints = AAZListType()
            properties.monitoring_interval_in_seconds = AAZIntType(
                serialized_name="monitoringIntervalInSeconds",
            )
            properties.monitoring_status = AAZStrType(
                serialized_name="monitoringStatus",
                flags={"read_only": True},
            )
            properties.notes = AAZStrType()
            properties.outputs = AAZListType()
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
                flags={"read_only": True},
            )
            properties.source = AAZObjectType()
            properties.start_time = AAZStrType(
                serialized_name="startTime",
                flags={"read_only": True},
            )
            properties.test_configurations = AAZListType(
                serialized_name="testConfigurations",
            )
            properties.test_groups = AAZListType(
                serialized_name="testGroups",
            )

            destination = cls._schema_on_200_201.properties.destination
            destination.address = AAZStrType()
            destination.port = AAZIntType()
            destination.resource_id = AAZStrType(
                serialized_name="resourceId",
            )

            endpoints = cls._schema_on_200_201.properties.endpoints
            endpoints.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.endpoints.Element
            _element.address = AAZStrType()
            _element.coverage_level = AAZStrType(
                serialized_name="coverageLevel",
            )
            _element.filter = AAZObjectType()
            _element.name = AAZStrType(
                flags={"required": True},
            )
            _element.resource_id = AAZStrType(
                serialized_name="resourceId",
            )
            _element.scope = AAZObjectType()
            _element.type = AAZStrType()

            filter = cls._schema_on_200_201.properties.endpoints.Element.filter
            filter.items = AAZListType()
            filter.type = AAZStrType()

            items = cls._schema_on_200_201.properties.endpoints.Element.filter.items
            items.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.endpoints.Element.filter.items.Element
            _element.address = AAZStrType()
            _element.type = AAZStrType()

            scope = cls._schema_on_200_201.properties.endpoints.Element.scope
            scope.exclude = AAZListType()
            scope.include = AAZListType()

            exclude = cls._schema_on_200_201.properties.endpoints.Element.scope.exclude
            exclude.Element = AAZObjectType()
            _CreateHelper._build_schema_connection_monitor_endpoint_scope_item_read(exclude.Element)

            include = cls._schema_on_200_201.properties.endpoints.Element.scope.include
            include.Element = AAZObjectType()
            _CreateHelper._build_schema_connection_monitor_endpoint_scope_item_read(include.Element)

            outputs = cls._schema_on_200_201.properties.outputs
            outputs.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.outputs.Element
            _element.type = AAZStrType()
            _element.workspace_settings = AAZObjectType(
                serialized_name="workspaceSettings",
            )

            workspace_settings = cls._schema_on_200_201.properties.outputs.Element.workspace_settings
            workspace_settings.workspace_resource_id = AAZStrType(
                serialized_name="workspaceResourceId",
            )

            source = cls._schema_on_200_201.properties.source
            source.port = AAZIntType()
            source.resource_id = AAZStrType(
                serialized_name="resourceId",
                flags={"required": True},
            )

            test_configurations = cls._schema_on_200_201.properties.test_configurations
            test_configurations.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.test_configurations.Element
            _element.http_configuration = AAZObjectType(
                serialized_name="httpConfiguration",
            )
            _element.icmp_configuration = AAZObjectType(
                serialized_name="icmpConfiguration",
            )
            _element.name = AAZStrType(
                flags={"required": True},
            )
            _element.preferred_ip_version = AAZStrType(
                serialized_name="preferredIPVersion",
            )
            _element.protocol = AAZStrType(
                flags={"required": True},
            )
            _element.success_threshold = AAZObjectType(
                serialized_name="successThreshold",
            )
            _element.tcp_configuration = AAZObjectType(
                serialized_name="tcpConfiguration",
            )
            _element.test_frequency_sec = AAZIntType(
                serialized_name="testFrequencySec",
            )

            http_configuration = cls._schema_on_200_201.properties.test_configurations.Element.http_configuration
            http_configuration.method = AAZStrType()
            http_configuration.path = AAZStrType()
            http_configuration.port = AAZIntType()
            http_configuration.prefer_https = AAZBoolType(
                serialized_name="preferHTTPS",
            )
            http_configuration.request_headers = AAZListType(
                serialized_name="requestHeaders",
            )
            http_configuration.valid_status_code_ranges = AAZListType(
                serialized_name="validStatusCodeRanges",
            )

            request_headers = cls._schema_on_200_201.properties.test_configurations.Element.http_configuration.request_headers
            request_headers.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.test_configurations.Element.http_configuration.request_headers.Element
            _element.name = AAZStrType()
            _element.value = AAZStrType()

            valid_status_code_ranges = cls._schema_on_200_201.properties.test_configurations.Element.http_configuration.valid_status_code_ranges
            valid_status_code_ranges.Element = AAZStrType()

            icmp_configuration = cls._schema_on_200_201.properties.test_configurations.Element.icmp_configuration
            icmp_configuration.disable_trace_route = AAZBoolType(
                serialized_name="disableTraceRoute",
            )

            success_threshold = cls._schema_on_200_201.properties.test_configurations.Element.success_threshold
            success_threshold.checks_failed_percent = AAZIntType(
                serialized_name="checksFailedPercent",
            )
            success_threshold.round_trip_time_ms = AAZFloatType(
                serialized_name="roundTripTimeMs",
            )

            tcp_configuration = cls._schema_on_200_201.properties.test_configurations.Element.tcp_configuration
            tcp_configuration.destination_port_behavior = AAZStrType(
                serialized_name="destinationPortBehavior",
            )
            tcp_configuration.disable_trace_route = AAZBoolType(
                serialized_name="disableTraceRoute",
            )
            tcp_configuration.port = AAZIntType()

            test_groups = cls._schema_on_200_201.properties.test_groups
            test_groups.Element = AAZObjectType()

            _element = cls._schema_on_200_201.properties.test_groups.Element
            _element.destinations = AAZListType(
                flags={"required": True},
            )
            _element.disable = AAZBoolType()
            _element.name = AAZStrType(
                flags={"required": True},
            )
            _element.sources = AAZListType(
                flags={"required": True},
            )
            _element.test_configurations = AAZListType(
                serialized_name="testConfigurations",
                flags={"required": True},
            )

            destinations = cls._schema_on_200_201.properties.test_groups.Element.destinations
            destinations.Element = AAZStrType()

            sources = cls._schema_on_200_201.properties.test_groups.Element.sources
            sources.Element = AAZStrType()

            test_configurations = cls._schema_on_200_201.properties.test_groups.Element.test_configurations
            test_configurations.Element = AAZStrType()

            tags = cls._schema_on_200_201.tags
            tags.Element = AAZStrType()

            return cls._schema_on_200_201


class _CreateHelper:
    """Helper class for Create"""

    @classmethod
    def _build_schema_connection_monitor_endpoint_scope_item_create(cls, _builder):
        if _builder is None:
            return
        _builder.set_prop("address", AAZStrType, ".address")

    _schema_connection_monitor_endpoint_scope_item_read = None

    @classmethod
    def _build_schema_connection_monitor_endpoint_scope_item_read(cls, _schema):
        if cls._schema_connection_monitor_endpoint_scope_item_read is not None:
            _schema.address = cls._schema_connection_monitor_endpoint_scope_item_read.address
            return

        cls._schema_connection_monitor_endpoint_scope_item_read = _schema_connection_monitor_endpoint_scope_item_read = AAZObjectType()

        connection_monitor_endpoint_scope_item_read = _schema_connection_monitor_endpoint_scope_item_read
        connection_monitor_endpoint_scope_item_read.address = AAZStrType()

        _schema.address = cls._schema_connection_monitor_endpoint_scope_item_read.address


__all__ = ["Create"]
