# --------------------------------------------------------------------------------------------
# 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(
    "monitor autoscale update",
)
class Update(AAZCommand):
    """Update an autoscale setting.

    For more information on autoscaling, visit: https://learn.microsoft.com/azure/monitoring-and-diagnostics/monitoring-understanding-autoscale-settings.

    :example: Update autoscale settings to use a fixed 3 instances by default.
        az monitor autoscale update -g myrg -n autoscale-name --count 3

    :example: Update autoscale settings to remove an email notification.
        az monitor autoscale update -g myrg -n autoscale-name --remove-action email bob@contoso.com

    :example: Update autoscale settings.
        az monitor autoscale update --count 3 --email-administrator true --enabled true --max-count 5 --min-count 2 --name MyAutoscaleSettings --resource-group MyResourceGroup --tags key[=value]
    """

    _aaz_info = {
        "version": "2022-10-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.insights/autoscalesettings/{}", "2022-10-01"],
        ]
    }

    AZ_SUPPORT_GENERIC_UPDATE = True

    def _handler(self, command_args):
        super()._handler(command_args)
        self._execute_operations()
        return 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.autoscale_name = AAZStrArg(
            options=["-n", "--name", "--autoscale-name"],
            help="The autoscale setting name.",
            required=True,
            id_part="name",
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.enabled = AAZBoolArg(
            options=["--enabled"],
            help="the enabled flag. Specifies whether automatic scaling is enabled for the resource. The default value is 'false'.",
            nullable=True,
        )
        _args_schema.tags = AAZDictArg(
            options=["--tags"],
            help="Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater in length than 128 characters and a value no greater in length than 256 characters.",
            nullable=True,
        )

        tags = cls._args_schema.tags
        tags.Element = AAZStrArg(
            nullable=True,
        )

        # define Arg Group "Predictive Policy"

        _args_schema = cls._args_schema
        _args_schema.scale_look_ahead_time = AAZDurationArg(
            options=["--scale-look-ahead-time"],
            arg_group="Predictive Policy",
            help="the amount of time to specify by which instances are launched in advance. It must be between 1 minute and 60 minutes in ISO 8601 format (for example, 100 days would be P100D).",
            nullable=True,
        )
        _args_schema.scale_mode = AAZStrArg(
            options=["--scale-mode"],
            arg_group="Predictive Policy",
            help="the predictive autoscale mode",
            enum={"Disabled": "Disabled", "Enabled": "Enabled", "ForecastOnly": "ForecastOnly"},
        )

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.notifications = AAZListArg(
            options=["--notifications"],
            arg_group="Properties",
            help="the collection of notifications.",
            nullable=True,
        )
        _args_schema.profiles = AAZListArg(
            options=["--profiles"],
            arg_group="Properties",
            help="the collection of automatic scaling profiles that specify different scaling parameters for different time periods. A maximum of 20 profiles can be specified.",
        )
        _args_schema.target_resource_location = AAZStrArg(
            options=["--target-resource-location"],
            arg_group="Properties",
            help="the location of the resource that the autoscale setting should be added to.",
            nullable=True,
        )
        _args_schema.target_resource_uri = AAZStrArg(
            options=["--target-resource-uri"],
            arg_group="Properties",
            help="the resource identifier of the resource that the autoscale setting should be added to.",
            nullable=True,
        )

        notifications = cls._args_schema.notifications
        notifications.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.notifications.Element
        _element.email = AAZObjectArg(
            options=["email"],
            help="the email notification.",
            nullable=True,
        )
        _element.operation = AAZStrArg(
            options=["operation"],
            help="the operation associated with the notification and its value must be \"scale\"",
            enum={"Scale": "Scale"},
        )
        _element.webhooks = AAZListArg(
            options=["webhooks"],
            help="the collection of webhook notifications.",
            nullable=True,
        )

        email = cls._args_schema.notifications.Element.email
        email.custom_emails = AAZListArg(
            options=["custom-emails"],
            help="the custom e-mails list. This value can be null or empty, in which case this attribute will be ignored.",
            nullable=True,
        )
        email.send_to_subscription_administrator = AAZBoolArg(
            options=["send-to-subscription-administrator"],
            help="a value indicating whether to send email to subscription administrator.",
            nullable=True,
        )
        email.send_to_subscription_co_administrators = AAZBoolArg(
            options=["send-to-subscription-co-administrators"],
            help="a value indicating whether to send email to subscription co-administrators.",
            nullable=True,
        )

        custom_emails = cls._args_schema.notifications.Element.email.custom_emails
        custom_emails.Element = AAZStrArg(
            nullable=True,
        )

        webhooks = cls._args_schema.notifications.Element.webhooks
        webhooks.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.notifications.Element.webhooks.Element
        _element.properties = AAZDictArg(
            options=["properties"],
            help="a property bag of settings. This value can be empty.",
            nullable=True,
        )
        _element.service_uri = AAZStrArg(
            options=["service-uri"],
            help="the service address to receive the notification.",
            nullable=True,
        )

        properties = cls._args_schema.notifications.Element.webhooks.Element.properties
        properties.Element = AAZStrArg(
            nullable=True,
        )

        profiles = cls._args_schema.profiles
        profiles.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.profiles.Element
        _element.capacity = AAZObjectArg(
            options=["capacity"],
            help="the number of instances that can be used during this profile.",
        )
        _element.fixed_date = AAZObjectArg(
            options=["fixed-date"],
            help="the specific date-time for the profile. This element is not used if the Recurrence element is used.",
            nullable=True,
        )
        _element.name = AAZStrArg(
            options=["name"],
            help="the name of the profile.",
        )
        _element.recurrence = AAZObjectArg(
            options=["recurrence"],
            help="the repeating times at which this profile begins. This element is not used if the FixedDate element is used.",
            nullable=True,
        )
        _element.rules = AAZListArg(
            options=["rules"],
            help="the collection of rules that provide the triggers and parameters for the scaling action. A maximum of 10 rules can be specified.",
        )

        capacity = cls._args_schema.profiles.Element.capacity
        capacity.default = AAZStrArg(
            options=["default"],
            help="the number of instances that will be set if metrics are not available for evaluation. The default is only used if the current instance count is lower than the default.",
        )
        capacity.maximum = AAZStrArg(
            options=["maximum"],
            help="the maximum number of instances for the resource. The actual maximum number of instances is limited by the cores that are available in the subscription.",
        )
        capacity.minimum = AAZStrArg(
            options=["minimum"],
            help="the minimum number of instances for the resource.",
        )

        fixed_date = cls._args_schema.profiles.Element.fixed_date
        fixed_date.end = AAZDateTimeArg(
            options=["end"],
            help="the end time for the profile in ISO 8601 format.",
        )
        fixed_date.start = AAZDateTimeArg(
            options=["start"],
            help="the start time for the profile in ISO 8601 format.",
        )
        fixed_date.time_zone = AAZStrArg(
            options=["time-zone"],
            help="the timezone of the start and end times for the profile. Some examples of valid time zones are: Dateline Standard Time, UTC-11, Hawaiian Standard Time, Alaskan Standard Time, Pacific Standard Time (Mexico), Pacific Standard Time, US Mountain Standard Time, Mountain Standard Time (Mexico), Mountain Standard Time, Central America Standard Time, Central Standard Time, Central Standard Time (Mexico), Canada Central Standard Time, SA Pacific Standard Time, Eastern Standard Time, US Eastern Standard Time, Venezuela Standard Time, Paraguay Standard Time, Atlantic Standard Time, Central Brazilian Standard Time, SA Western Standard Time, Pacific SA Standard Time, Newfoundland Standard Time, E. South America Standard Time, Argentina Standard Time, SA Eastern Standard Time, Greenland Standard Time, Montevideo Standard Time, Bahia Standard Time, UTC-02, Mid-Atlantic Standard Time, Azores Standard Time, Cape Verde Standard Time, Morocco Standard Time, UTC, GMT Standard Time, Greenwich Standard Time, W. Europe Standard Time, Central Europe Standard Time, Romance Standard Time, Central European Standard Time, W. Central Africa Standard Time, Namibia Standard Time, Jordan Standard Time, GTB Standard Time, Middle East Standard Time, Egypt Standard Time, Syria Standard Time, E. Europe Standard Time, South Africa Standard Time, FLE Standard Time, Turkey Standard Time, Israel Standard Time, Kaliningrad Standard Time, Libya Standard Time, Arabic Standard Time, Arab Standard Time, Belarus Standard Time, Russian Standard Time, E. Africa Standard Time, Iran Standard Time, Arabian Standard Time, Azerbaijan Standard Time, Russia Time Zone 3, Mauritius Standard Time, Georgian Standard Time, Caucasus Standard Time, Afghanistan Standard Time, West Asia Standard Time, Ekaterinburg Standard Time, Pakistan Standard Time, India Standard Time, Sri Lanka Standard Time, Nepal Standard Time, Central Asia Standard Time, Bangladesh Standard Time, N. Central Asia Standard Time, Myanmar Standard Time, SE Asia Standard Time, North Asia Standard Time, China Standard Time, North Asia East Standard Time, Singapore Standard Time, W. Australia Standard Time, Taipei Standard Time, Ulaanbaatar Standard Time, Tokyo Standard Time, Korea Standard Time, Yakutsk Standard Time, Cen. Australia Standard Time, AUS Central Standard Time, E. Australia Standard Time, AUS Eastern Standard Time, West Pacific Standard Time, Tasmania Standard Time, Magadan Standard Time, Vladivostok Standard Time, Russia Time Zone 10, Central Pacific Standard Time, Russia Time Zone 11, New Zealand Standard Time, UTC+12, Fiji Standard Time, Kamchatka Standard Time, Tonga Standard Time, Samoa Standard Time, Line Islands Standard Time",
            nullable=True,
        )

        recurrence = cls._args_schema.profiles.Element.recurrence
        recurrence.frequency = AAZStrArg(
            options=["frequency"],
            help="the recurrence frequency. How often the schedule profile should take effect. This value must be Week, meaning each week will have the same set of profiles. For example, to set a daily schedule, set **schedule** to every day of the week. The frequency property specifies that the schedule is repeated weekly.",
            enum={"Day": "Day", "Hour": "Hour", "Minute": "Minute", "Month": "Month", "None": "None", "Second": "Second", "Week": "Week", "Year": "Year"},
        )
        recurrence.schedule = AAZObjectArg(
            options=["schedule"],
            help="the scheduling constraints for when the profile begins.",
        )

        schedule = cls._args_schema.profiles.Element.recurrence.schedule
        schedule.days = AAZListArg(
            options=["days"],
            help="the collection of days that the profile takes effect on. Possible values are Sunday through Saturday.",
        )
        schedule.hours = AAZListArg(
            options=["hours"],
            help="A collection of hours that the profile takes effect on. Values supported are 0 to 23 on the 24-hour clock (AM/PM times are not supported).",
        )
        schedule.minutes = AAZListArg(
            options=["minutes"],
            help="A collection of minutes at which the profile takes effect at.",
        )
        schedule.time_zone = AAZStrArg(
            options=["time-zone"],
            help="the timezone for the hours of the profile. Some examples of valid time zones are: Dateline Standard Time, UTC-11, Hawaiian Standard Time, Alaskan Standard Time, Pacific Standard Time (Mexico), Pacific Standard Time, US Mountain Standard Time, Mountain Standard Time (Mexico), Mountain Standard Time, Central America Standard Time, Central Standard Time, Central Standard Time (Mexico), Canada Central Standard Time, SA Pacific Standard Time, Eastern Standard Time, US Eastern Standard Time, Venezuela Standard Time, Paraguay Standard Time, Atlantic Standard Time, Central Brazilian Standard Time, SA Western Standard Time, Pacific SA Standard Time, Newfoundland Standard Time, E. South America Standard Time, Argentina Standard Time, SA Eastern Standard Time, Greenland Standard Time, Montevideo Standard Time, Bahia Standard Time, UTC-02, Mid-Atlantic Standard Time, Azores Standard Time, Cape Verde Standard Time, Morocco Standard Time, UTC, GMT Standard Time, Greenwich Standard Time, W. Europe Standard Time, Central Europe Standard Time, Romance Standard Time, Central European Standard Time, W. Central Africa Standard Time, Namibia Standard Time, Jordan Standard Time, GTB Standard Time, Middle East Standard Time, Egypt Standard Time, Syria Standard Time, E. Europe Standard Time, South Africa Standard Time, FLE Standard Time, Turkey Standard Time, Israel Standard Time, Kaliningrad Standard Time, Libya Standard Time, Arabic Standard Time, Arab Standard Time, Belarus Standard Time, Russian Standard Time, E. Africa Standard Time, Iran Standard Time, Arabian Standard Time, Azerbaijan Standard Time, Russia Time Zone 3, Mauritius Standard Time, Georgian Standard Time, Caucasus Standard Time, Afghanistan Standard Time, West Asia Standard Time, Ekaterinburg Standard Time, Pakistan Standard Time, India Standard Time, Sri Lanka Standard Time, Nepal Standard Time, Central Asia Standard Time, Bangladesh Standard Time, N. Central Asia Standard Time, Myanmar Standard Time, SE Asia Standard Time, North Asia Standard Time, China Standard Time, North Asia East Standard Time, Singapore Standard Time, W. Australia Standard Time, Taipei Standard Time, Ulaanbaatar Standard Time, Tokyo Standard Time, Korea Standard Time, Yakutsk Standard Time, Cen. Australia Standard Time, AUS Central Standard Time, E. Australia Standard Time, AUS Eastern Standard Time, West Pacific Standard Time, Tasmania Standard Time, Magadan Standard Time, Vladivostok Standard Time, Russia Time Zone 10, Central Pacific Standard Time, Russia Time Zone 11, New Zealand Standard Time, UTC+12, Fiji Standard Time, Kamchatka Standard Time, Tonga Standard Time, Samoa Standard Time, Line Islands Standard Time",
        )

        days = cls._args_schema.profiles.Element.recurrence.schedule.days
        days.Element = AAZStrArg(
            nullable=True,
        )

        hours = cls._args_schema.profiles.Element.recurrence.schedule.hours
        hours.Element = AAZIntArg(
            nullable=True,
        )

        minutes = cls._args_schema.profiles.Element.recurrence.schedule.minutes
        minutes.Element = AAZIntArg(
            nullable=True,
        )

        rules = cls._args_schema.profiles.Element.rules
        rules.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.profiles.Element.rules.Element
        _element.metric_trigger = AAZObjectArg(
            options=["metric-trigger"],
            help="the trigger that results in a scaling action.",
        )
        _element.scale_action = AAZObjectArg(
            options=["scale-action"],
            help="the parameters for the scaling action.",
        )

        metric_trigger = cls._args_schema.profiles.Element.rules.Element.metric_trigger
        metric_trigger.dimensions = AAZListArg(
            options=["dimensions"],
            help="List of dimension conditions. For example: [{\"DimensionName\":\"AppName\",\"Operator\":\"Equals\",\"Values\":[\"App1\"]},{\"DimensionName\":\"Deployment\",\"Operator\":\"Equals\",\"Values\":[\"default\"]}].",
            nullable=True,
        )
        metric_trigger.divide_per_instance = AAZBoolArg(
            options=["divide-per-instance"],
            help="a value indicating whether metric should divide per instance.",
            nullable=True,
        )
        metric_trigger.metric_name = AAZStrArg(
            options=["metric-name"],
            help="the name of the metric that defines what the rule monitors.",
        )
        metric_trigger.metric_namespace = AAZStrArg(
            options=["metric-namespace"],
            help="the namespace of the metric that defines what the rule monitors.",
            nullable=True,
        )
        metric_trigger.metric_resource_location = AAZStrArg(
            options=["metric-resource-location"],
            help="the location of the resource the rule monitors.",
            nullable=True,
        )
        metric_trigger.metric_resource_uri = AAZStrArg(
            options=["metric-resource-uri"],
            help="the resource identifier of the resource the rule monitors.",
        )
        metric_trigger.operator = AAZStrArg(
            options=["operator"],
            help="the operator that is used to compare the metric data and the threshold.",
            enum={"Equals": "Equals", "GreaterThan": "GreaterThan", "GreaterThanOrEqual": "GreaterThanOrEqual", "LessThan": "LessThan", "LessThanOrEqual": "LessThanOrEqual", "NotEquals": "NotEquals"},
        )
        metric_trigger.statistic = AAZStrArg(
            options=["statistic"],
            help="the metric statistic type. How the metrics from multiple instances are combined.",
            enum={"Average": "Average", "Count": "Count", "Max": "Max", "Min": "Min", "Sum": "Sum"},
        )
        metric_trigger.threshold = AAZFloatArg(
            options=["threshold"],
            help="the threshold of the metric that triggers the scale action.",
        )
        metric_trigger.time_aggregation = AAZStrArg(
            options=["time-aggregation"],
            help="time aggregation type. How the data that is collected should be combined over time. The default value is Average.",
            enum={"Average": "Average", "Count": "Count", "Last": "Last", "Maximum": "Maximum", "Minimum": "Minimum", "Total": "Total"},
        )
        metric_trigger.time_grain = AAZDurationArg(
            options=["time-grain"],
            help="the granularity of metrics the rule monitors. Must be one of the predefined values returned from metric definitions for the metric. Must be between 12 hours and 1 minute.",
        )
        metric_trigger.time_window = AAZDurationArg(
            options=["time-window"],
            help="the range of time in which instance data is collected. This value must be greater than the delay in metric collection, which can vary from resource-to-resource. Must be between 12 hours and 5 minutes.",
        )

        dimensions = cls._args_schema.profiles.Element.rules.Element.metric_trigger.dimensions
        dimensions.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.profiles.Element.rules.Element.metric_trigger.dimensions.Element
        _element.dimension_name = AAZStrArg(
            options=["dimension-name"],
            help="Name of the dimension.",
        )
        _element.operator = AAZStrArg(
            options=["operator"],
            help="the dimension operator. Only 'Equals' and 'NotEquals' are supported. 'Equals' being equal to any of the values. 'NotEquals' being not equal to all of the values",
            enum={"Equals": "Equals", "NotEquals": "NotEquals"},
        )
        _element.values = AAZListArg(
            options=["values"],
            help="list of dimension values. For example: [\"App1\",\"App2\"].",
        )

        values = cls._args_schema.profiles.Element.rules.Element.metric_trigger.dimensions.Element.values
        values.Element = AAZStrArg(
            nullable=True,
        )

        scale_action = cls._args_schema.profiles.Element.rules.Element.scale_action
        scale_action.cooldown = AAZDurationArg(
            options=["cooldown"],
            help="the amount of time to wait since the last scaling action before this action occurs. It must be between 1 week and 1 minute in ISO 8601 format.",
        )
        scale_action.direction = AAZStrArg(
            options=["direction"],
            help="the scale direction. Whether the scaling action increases or decreases the number of instances.",
            enum={"Decrease": "Decrease", "Increase": "Increase", "None": "None"},
        )
        scale_action.type = AAZStrArg(
            options=["type"],
            help="the type of action that should occur when the scale rule fires.",
            enum={"ChangeCount": "ChangeCount", "ExactCount": "ExactCount", "PercentChangeCount": "PercentChangeCount", "ServiceAllowedNextValue": "ServiceAllowedNextValue"},
        )
        scale_action.value = AAZStrArg(
            options=["value"],
            help="the number of instances that are involved in the scaling action. This value must be 1 or greater. The default value is 1.",
            nullable=True,
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.AutoscaleSettingsGet(ctx=self.ctx)()
        self.pre_instance_update(self.ctx.vars.instance)
        self.InstanceUpdateByJson(ctx=self.ctx)()
        self.InstanceUpdateByGeneric(ctx=self.ctx)()
        self.post_instance_update(self.ctx.vars.instance)
        self.AutoscaleSettingsCreateOrUpdate(ctx=self.ctx)()
        self.post_operations()

    @register_callback
    def pre_operations(self):
        pass

    @register_callback
    def post_operations(self):
        pass

    @register_callback
    def pre_instance_update(self, instance):
        pass

    @register_callback
    def post_instance_update(self, instance):
        pass

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

    class AutoscaleSettingsGet(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 [200]:
                return self.on_200(session)

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "autoscaleSettingName", self.ctx.args.autoscale_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(
                    "api-version", "2022-10-01",
                    required=True,
                ),
            }
            return parameters

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

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

        _schema_on_200 = None

        @classmethod
        def _build_schema_on_200(cls):
            if cls._schema_on_200 is not None:
                return cls._schema_on_200

            cls._schema_on_200 = AAZObjectType()
            _UpdateHelper._build_schema_autoscale_setting_resource_read(cls._schema_on_200)

            return cls._schema_on_200

    class AutoscaleSettingsCreateOrUpdate(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 [200, 201]:
                return self.on_200_201(session)

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/autoscalesettings/{autoscaleSettingName}",
                **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(
                    "autoscaleSettingName", self.ctx.args.autoscale_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(
                    "api-version", "2022-10-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,
                value=self.ctx.vars.instance,
            )

            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()
            _UpdateHelper._build_schema_autoscale_setting_resource_read(cls._schema_on_200_201)

            return cls._schema_on_200_201

    class InstanceUpdateByJson(AAZJsonInstanceUpdateOperation):

        def __call__(self, *args, **kwargs):
            self._update_instance(self.ctx.vars.instance)

        def _update_instance(self, instance):
            _instance_value, _builder = self.new_content_builder(
                self.ctx.args,
                value=instance,
                typ=AAZObjectType
            )
            _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("enabled", AAZBoolType, ".enabled")
                properties.set_prop("name", AAZStrType, ".autoscale_name")
                properties.set_prop("notifications", AAZListType, ".notifications")
                properties.set_prop("predictiveAutoscalePolicy", AAZObjectType)
                properties.set_prop("profiles", AAZListType, ".profiles", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("targetResourceLocation", AAZStrType, ".target_resource_location")
                properties.set_prop("targetResourceUri", AAZStrType, ".target_resource_uri")

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

            _elements = _builder.get(".properties.notifications[]")
            if _elements is not None:
                _elements.set_prop("email", AAZObjectType, ".email")
                _elements.set_prop("operation", AAZStrType, ".operation", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("webhooks", AAZListType, ".webhooks")

            email = _builder.get(".properties.notifications[].email")
            if email is not None:
                email.set_prop("customEmails", AAZListType, ".custom_emails")
                email.set_prop("sendToSubscriptionAdministrator", AAZBoolType, ".send_to_subscription_administrator")
                email.set_prop("sendToSubscriptionCoAdministrators", AAZBoolType, ".send_to_subscription_co_administrators")

            custom_emails = _builder.get(".properties.notifications[].email.customEmails")
            if custom_emails is not None:
                custom_emails.set_elements(AAZStrType, ".")

            webhooks = _builder.get(".properties.notifications[].webhooks")
            if webhooks is not None:
                webhooks.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.notifications[].webhooks[]")
            if _elements is not None:
                _elements.set_prop("properties", AAZDictType, ".properties")
                _elements.set_prop("serviceUri", AAZStrType, ".service_uri")

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

            predictive_autoscale_policy = _builder.get(".properties.predictiveAutoscalePolicy")
            if predictive_autoscale_policy is not None:
                predictive_autoscale_policy.set_prop("scaleLookAheadTime", AAZStrType, ".scale_look_ahead_time")
                predictive_autoscale_policy.set_prop("scaleMode", AAZStrType, ".scale_mode", typ_kwargs={"flags": {"required": True}})

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

            _elements = _builder.get(".properties.profiles[]")
            if _elements is not None:
                _elements.set_prop("capacity", AAZObjectType, ".capacity", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("fixedDate", AAZObjectType, ".fixed_date")
                _elements.set_prop("name", AAZStrType, ".name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("recurrence", AAZObjectType, ".recurrence")
                _elements.set_prop("rules", AAZListType, ".rules", typ_kwargs={"flags": {"required": True}})

            capacity = _builder.get(".properties.profiles[].capacity")
            if capacity is not None:
                capacity.set_prop("default", AAZStrType, ".default", typ_kwargs={"flags": {"required": True}})
                capacity.set_prop("maximum", AAZStrType, ".maximum", typ_kwargs={"flags": {"required": True}})
                capacity.set_prop("minimum", AAZStrType, ".minimum", typ_kwargs={"flags": {"required": True}})

            fixed_date = _builder.get(".properties.profiles[].fixedDate")
            if fixed_date is not None:
                fixed_date.set_prop("end", AAZStrType, ".end", typ_kwargs={"flags": {"required": True}})
                fixed_date.set_prop("start", AAZStrType, ".start", typ_kwargs={"flags": {"required": True}})
                fixed_date.set_prop("timeZone", AAZStrType, ".time_zone")

            recurrence = _builder.get(".properties.profiles[].recurrence")
            if recurrence is not None:
                recurrence.set_prop("frequency", AAZStrType, ".frequency", typ_kwargs={"flags": {"required": True}})
                recurrence.set_prop("schedule", AAZObjectType, ".schedule", typ_kwargs={"flags": {"required": True}})

            schedule = _builder.get(".properties.profiles[].recurrence.schedule")
            if schedule is not None:
                schedule.set_prop("days", AAZListType, ".days", typ_kwargs={"flags": {"required": True}})
                schedule.set_prop("hours", AAZListType, ".hours", typ_kwargs={"flags": {"required": True}})
                schedule.set_prop("minutes", AAZListType, ".minutes", typ_kwargs={"flags": {"required": True}})
                schedule.set_prop("timeZone", AAZStrType, ".time_zone", typ_kwargs={"flags": {"required": True}})

            days = _builder.get(".properties.profiles[].recurrence.schedule.days")
            if days is not None:
                days.set_elements(AAZStrType, ".")

            hours = _builder.get(".properties.profiles[].recurrence.schedule.hours")
            if hours is not None:
                hours.set_elements(AAZIntType, ".")

            minutes = _builder.get(".properties.profiles[].recurrence.schedule.minutes")
            if minutes is not None:
                minutes.set_elements(AAZIntType, ".")

            rules = _builder.get(".properties.profiles[].rules")
            if rules is not None:
                rules.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.profiles[].rules[]")
            if _elements is not None:
                _elements.set_prop("metricTrigger", AAZObjectType, ".metric_trigger", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("scaleAction", AAZObjectType, ".scale_action", typ_kwargs={"flags": {"required": True}})

            metric_trigger = _builder.get(".properties.profiles[].rules[].metricTrigger")
            if metric_trigger is not None:
                metric_trigger.set_prop("dimensions", AAZListType, ".dimensions")
                metric_trigger.set_prop("dividePerInstance", AAZBoolType, ".divide_per_instance")
                metric_trigger.set_prop("metricName", AAZStrType, ".metric_name", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("metricNamespace", AAZStrType, ".metric_namespace")
                metric_trigger.set_prop("metricResourceLocation", AAZStrType, ".metric_resource_location")
                metric_trigger.set_prop("metricResourceUri", AAZStrType, ".metric_resource_uri", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("operator", AAZStrType, ".operator", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("statistic", AAZStrType, ".statistic", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("threshold", AAZFloatType, ".threshold", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("timeAggregation", AAZStrType, ".time_aggregation", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("timeGrain", AAZStrType, ".time_grain", typ_kwargs={"flags": {"required": True}})
                metric_trigger.set_prop("timeWindow", AAZStrType, ".time_window", typ_kwargs={"flags": {"required": True}})

            dimensions = _builder.get(".properties.profiles[].rules[].metricTrigger.dimensions")
            if dimensions is not None:
                dimensions.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.profiles[].rules[].metricTrigger.dimensions[]")
            if _elements is not None:
                _elements.set_prop("DimensionName", AAZStrType, ".dimension_name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("Operator", AAZStrType, ".operator", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("Values", AAZListType, ".values", typ_kwargs={"flags": {"required": True}})

            values = _builder.get(".properties.profiles[].rules[].metricTrigger.dimensions[].Values")
            if values is not None:
                values.set_elements(AAZStrType, ".")

            scale_action = _builder.get(".properties.profiles[].rules[].scaleAction")
            if scale_action is not None:
                scale_action.set_prop("cooldown", AAZStrType, ".cooldown", typ_kwargs={"flags": {"required": True}})
                scale_action.set_prop("direction", AAZStrType, ".direction", typ_kwargs={"flags": {"required": True}})
                scale_action.set_prop("type", AAZStrType, ".type", typ_kwargs={"flags": {"required": True}})
                scale_action.set_prop("value", AAZStrType, ".value")

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

            return _instance_value

    class InstanceUpdateByGeneric(AAZGenericInstanceUpdateOperation):

        def __call__(self, *args, **kwargs):
            self._update_instance_by_generic(
                self.ctx.vars.instance,
                self.ctx.generic_update_args
            )


class _UpdateHelper:
    """Helper class for Update"""

    _schema_autoscale_setting_resource_read = None

    @classmethod
    def _build_schema_autoscale_setting_resource_read(cls, _schema):
        if cls._schema_autoscale_setting_resource_read is not None:
            _schema.id = cls._schema_autoscale_setting_resource_read.id
            _schema.location = cls._schema_autoscale_setting_resource_read.location
            _schema.name = cls._schema_autoscale_setting_resource_read.name
            _schema.properties = cls._schema_autoscale_setting_resource_read.properties
            _schema.system_data = cls._schema_autoscale_setting_resource_read.system_data
            _schema.tags = cls._schema_autoscale_setting_resource_read.tags
            _schema.type = cls._schema_autoscale_setting_resource_read.type
            return

        cls._schema_autoscale_setting_resource_read = _schema_autoscale_setting_resource_read = AAZObjectType()

        autoscale_setting_resource_read = _schema_autoscale_setting_resource_read
        autoscale_setting_resource_read.id = AAZStrType(
            flags={"read_only": True},
        )
        autoscale_setting_resource_read.location = AAZStrType(
            flags={"required": True},
        )
        autoscale_setting_resource_read.name = AAZStrType(
            flags={"read_only": True},
        )
        autoscale_setting_resource_read.properties = AAZObjectType(
            flags={"required": True, "client_flatten": True},
        )
        autoscale_setting_resource_read.system_data = AAZObjectType(
            serialized_name="systemData",
            flags={"read_only": True},
        )
        cls._build_schema_system_data_read(autoscale_setting_resource_read.system_data)
        autoscale_setting_resource_read.tags = AAZDictType()
        autoscale_setting_resource_read.type = AAZStrType(
            flags={"read_only": True},
        )

        properties = _schema_autoscale_setting_resource_read.properties
        properties.enabled = AAZBoolType()
        properties.name = AAZStrType()
        properties.notifications = AAZListType()
        properties.predictive_autoscale_policy = AAZObjectType(
            serialized_name="predictiveAutoscalePolicy",
        )
        properties.profiles = AAZListType(
            flags={"required": True},
        )
        properties.target_resource_location = AAZStrType(
            serialized_name="targetResourceLocation",
        )
        properties.target_resource_uri = AAZStrType(
            serialized_name="targetResourceUri",
        )

        notifications = _schema_autoscale_setting_resource_read.properties.notifications
        notifications.Element = AAZObjectType()

        _element = _schema_autoscale_setting_resource_read.properties.notifications.Element
        _element.email = AAZObjectType()
        _element.operation = AAZStrType(
            flags={"required": True},
        )
        _element.webhooks = AAZListType()

        email = _schema_autoscale_setting_resource_read.properties.notifications.Element.email
        email.custom_emails = AAZListType(
            serialized_name="customEmails",
        )
        email.send_to_subscription_administrator = AAZBoolType(
            serialized_name="sendToSubscriptionAdministrator",
        )
        email.send_to_subscription_co_administrators = AAZBoolType(
            serialized_name="sendToSubscriptionCoAdministrators",
        )

        custom_emails = _schema_autoscale_setting_resource_read.properties.notifications.Element.email.custom_emails
        custom_emails.Element = AAZStrType()

        webhooks = _schema_autoscale_setting_resource_read.properties.notifications.Element.webhooks
        webhooks.Element = AAZObjectType()

        _element = _schema_autoscale_setting_resource_read.properties.notifications.Element.webhooks.Element
        _element.properties = AAZDictType()
        _element.service_uri = AAZStrType(
            serialized_name="serviceUri",
        )

        properties = _schema_autoscale_setting_resource_read.properties.notifications.Element.webhooks.Element.properties
        properties.Element = AAZStrType()

        predictive_autoscale_policy = _schema_autoscale_setting_resource_read.properties.predictive_autoscale_policy
        predictive_autoscale_policy.scale_look_ahead_time = AAZStrType(
            serialized_name="scaleLookAheadTime",
        )
        predictive_autoscale_policy.scale_mode = AAZStrType(
            serialized_name="scaleMode",
            flags={"required": True},
        )

        profiles = _schema_autoscale_setting_resource_read.properties.profiles
        profiles.Element = AAZObjectType()

        _element = _schema_autoscale_setting_resource_read.properties.profiles.Element
        _element.capacity = AAZObjectType(
            flags={"required": True},
        )
        _element.fixed_date = AAZObjectType(
            serialized_name="fixedDate",
        )
        _element.name = AAZStrType(
            flags={"required": True},
        )
        _element.recurrence = AAZObjectType()
        _element.rules = AAZListType(
            flags={"required": True},
        )

        capacity = _schema_autoscale_setting_resource_read.properties.profiles.Element.capacity
        capacity.default = AAZStrType(
            flags={"required": True},
        )
        capacity.maximum = AAZStrType(
            flags={"required": True},
        )
        capacity.minimum = AAZStrType(
            flags={"required": True},
        )

        fixed_date = _schema_autoscale_setting_resource_read.properties.profiles.Element.fixed_date
        fixed_date.end = AAZStrType(
            flags={"required": True},
        )
        fixed_date.start = AAZStrType(
            flags={"required": True},
        )
        fixed_date.time_zone = AAZStrType(
            serialized_name="timeZone",
        )

        recurrence = _schema_autoscale_setting_resource_read.properties.profiles.Element.recurrence
        recurrence.frequency = AAZStrType(
            flags={"required": True},
        )
        recurrence.schedule = AAZObjectType(
            flags={"required": True},
        )

        schedule = _schema_autoscale_setting_resource_read.properties.profiles.Element.recurrence.schedule
        schedule.days = AAZListType(
            flags={"required": True},
        )
        schedule.hours = AAZListType(
            flags={"required": True},
        )
        schedule.minutes = AAZListType(
            flags={"required": True},
        )
        schedule.time_zone = AAZStrType(
            serialized_name="timeZone",
            flags={"required": True},
        )

        days = _schema_autoscale_setting_resource_read.properties.profiles.Element.recurrence.schedule.days
        days.Element = AAZStrType()

        hours = _schema_autoscale_setting_resource_read.properties.profiles.Element.recurrence.schedule.hours
        hours.Element = AAZIntType()

        minutes = _schema_autoscale_setting_resource_read.properties.profiles.Element.recurrence.schedule.minutes
        minutes.Element = AAZIntType()

        rules = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules
        rules.Element = AAZObjectType()

        _element = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element
        _element.metric_trigger = AAZObjectType(
            serialized_name="metricTrigger",
            flags={"required": True},
        )
        _element.scale_action = AAZObjectType(
            serialized_name="scaleAction",
            flags={"required": True},
        )

        metric_trigger = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element.metric_trigger
        metric_trigger.dimensions = AAZListType()
        metric_trigger.divide_per_instance = AAZBoolType(
            serialized_name="dividePerInstance",
        )
        metric_trigger.metric_name = AAZStrType(
            serialized_name="metricName",
            flags={"required": True},
        )
        metric_trigger.metric_namespace = AAZStrType(
            serialized_name="metricNamespace",
        )
        metric_trigger.metric_resource_location = AAZStrType(
            serialized_name="metricResourceLocation",
        )
        metric_trigger.metric_resource_uri = AAZStrType(
            serialized_name="metricResourceUri",
            flags={"required": True},
        )
        metric_trigger.operator = AAZStrType(
            flags={"required": True},
        )
        metric_trigger.statistic = AAZStrType(
            flags={"required": True},
        )
        metric_trigger.threshold = AAZFloatType(
            flags={"required": True},
        )
        metric_trigger.time_aggregation = AAZStrType(
            serialized_name="timeAggregation",
            flags={"required": True},
        )
        metric_trigger.time_grain = AAZStrType(
            serialized_name="timeGrain",
            flags={"required": True},
        )
        metric_trigger.time_window = AAZStrType(
            serialized_name="timeWindow",
            flags={"required": True},
        )

        dimensions = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element.metric_trigger.dimensions
        dimensions.Element = AAZObjectType()

        _element = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element.metric_trigger.dimensions.Element
        _element.dimension_name = AAZStrType(
            serialized_name="DimensionName",
            flags={"required": True},
        )
        _element.operator = AAZStrType(
            serialized_name="Operator",
            flags={"required": True},
        )
        _element.values = AAZListType(
            serialized_name="Values",
            flags={"required": True},
        )

        values = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element.metric_trigger.dimensions.Element.values
        values.Element = AAZStrType()

        scale_action = _schema_autoscale_setting_resource_read.properties.profiles.Element.rules.Element.scale_action
        scale_action.cooldown = AAZStrType(
            flags={"required": True},
        )
        scale_action.direction = AAZStrType(
            flags={"required": True},
        )
        scale_action.type = AAZStrType(
            flags={"required": True},
        )
        scale_action.value = AAZStrType()

        tags = _schema_autoscale_setting_resource_read.tags
        tags.Element = AAZStrType()

        _schema.id = cls._schema_autoscale_setting_resource_read.id
        _schema.location = cls._schema_autoscale_setting_resource_read.location
        _schema.name = cls._schema_autoscale_setting_resource_read.name
        _schema.properties = cls._schema_autoscale_setting_resource_read.properties
        _schema.system_data = cls._schema_autoscale_setting_resource_read.system_data
        _schema.tags = cls._schema_autoscale_setting_resource_read.tags
        _schema.type = cls._schema_autoscale_setting_resource_read.type

    _schema_system_data_read = None

    @classmethod
    def _build_schema_system_data_read(cls, _schema):
        if cls._schema_system_data_read is not None:
            _schema.created_at = cls._schema_system_data_read.created_at
            _schema.created_by = cls._schema_system_data_read.created_by
            _schema.created_by_type = cls._schema_system_data_read.created_by_type
            _schema.last_modified_at = cls._schema_system_data_read.last_modified_at
            _schema.last_modified_by = cls._schema_system_data_read.last_modified_by
            _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type
            return

        cls._schema_system_data_read = _schema_system_data_read = AAZObjectType(
            flags={"read_only": True}
        )

        system_data_read = _schema_system_data_read
        system_data_read.created_at = AAZStrType(
            serialized_name="createdAt",
        )
        system_data_read.created_by = AAZStrType(
            serialized_name="createdBy",
        )
        system_data_read.created_by_type = AAZStrType(
            serialized_name="createdByType",
        )
        system_data_read.last_modified_at = AAZStrType(
            serialized_name="lastModifiedAt",
        )
        system_data_read.last_modified_by = AAZStrType(
            serialized_name="lastModifiedBy",
        )
        system_data_read.last_modified_by_type = AAZStrType(
            serialized_name="lastModifiedByType",
        )

        _schema.created_at = cls._schema_system_data_read.created_at
        _schema.created_by = cls._schema_system_data_read.created_by
        _schema.created_by_type = cls._schema_system_data_read.created_by_type
        _schema.last_modified_at = cls._schema_system_data_read.last_modified_at
        _schema.last_modified_by = cls._schema_system_data_read.last_modified_by
        _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type


__all__ = ["Update"]
