# --------------------------------------------------------------------------------------------
# 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 sli update",
    is_preview=True,
)
class Update(AAZCommand):
    """Update an SLI resource.

    Managed-identity changes must be applied to all three surfaces in a single
    PUT, because the service validates set-equality across them:

      1. ``identity.userAssignedIdentities`` (top-level ARM identity dictionary).
      2. ``properties.destinationAmwAccounts[].identity``.
      3. ``properties.sliProperties.{signals|goodSignals|totalSignals}.signalSources[].sourceAmwAccountManagedIdentity``.

    Window-based SLIs populate the ``signals`` slot; request-based SLIs populate
    ``goodSignals`` and ``totalSignals``. Run ``az monitor sli show`` first to
    confirm the destination/signal-source indices and which slot is in use.
    The examples below assume the window-based ``signals`` slot with one
    destination AMW and one signal source.

    Note: UAMI ARM IDs contain ``.`` (for example ``Microsoft.ManagedIdentity``),
    so they cannot be addressed as path segments by ``--set/--remove`` (azure-cli
    splits the path on ``.``). To change ``identity.userAssignedIdentities``,
    replace the whole map by passing a JSON value rooted at ``identity.userAssignedIdentities``.

    :example: Update the description.
        az monitor sli update --service-group-name MyServiceGroup --sli-name MySli --set properties.description="Updated API availability SLI"

    :example: Rotate the source-AMW managed identity (signal source 0) to a new UAMI.
        az monitor sli update --service-group-name MyServiceGroup --sli-name MySli --set 'identity.userAssignedIdentities={"<new-source-uami-arm-id>":{}}' --set 'properties.sliProperties.signals.signalSources[0].sourceAmwAccountManagedIdentity=<new-source-uami-arm-id>'

    :example: Rotate the destination-AMW managed identity (destination 0) to a new UAMI.
        az monitor sli update --service-group-name MyServiceGroup --sli-name MySli --set 'identity.userAssignedIdentities={"<new-destination-uami-arm-id>":{}}' --set 'properties.destinationAmwAccounts[0].identity=<new-destination-uami-arm-id>'

    :example: Rotate the source-AMW and destination-AMW managed identities together in a single update (single UAMI used for both).
        az monitor sli update --service-group-name MyServiceGroup --sli-name MySli --set 'identity.userAssignedIdentities={"<new-uami-arm-id>":{}}' --set 'properties.destinationAmwAccounts[0].identity=<new-uami-arm-id>' --set 'properties.sliProperties.signals.signalSources[0].sourceAmwAccountManagedIdentity=<new-uami-arm-id>'
    """

    _aaz_info = {
        "version": "2025-03-01-preview",
        "resources": [
            ["mgmt-plane", "/providers/microsoft.management/servicegroups/{}/providers/microsoft.monitor/slis/{}", "2025-03-01-preview"],
        ]
    }

    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.service_group_name = AAZStrArg(
            options=["--service-group-name"],
            help="The name of the service group.",
            required=True,
            fmt=AAZStrArgFormat(
                pattern="^[A-Za-z0-9._()~-]{1,250}$",
            ),
        )
        _args_schema.sli_name = AAZStrArg(
            options=["--sli-name"],
            help="Name of the SLI that is given by the user.",
            required=True,
            fmt=AAZStrArgFormat(
                pattern="^[a-zA-Z0-9][a-zA-Z0-9_()~-]{2,63}$",
            ),
        )

        # define Arg Group "Identity"

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.baseline_properties = AAZObjectArg(
            options=["--baseline-properties"],
            arg_group="Properties",
            help="Defines the SLO baseline associated with the SLI.",
        )
        _args_schema.category = AAZStrArg(
            options=["--category"],
            arg_group="Properties",
            help="Specifies the category of the SLI, used to classify signals such as Availability and Latency.",
            enum={"Availability": "Availability", "Latency": "Latency"},
        )
        _args_schema.description = AAZStrArg(
            options=["--description"],
            arg_group="Properties",
            help="A user-provided description of the SLI, with a maximum length of 1000 characters.",
            fmt=AAZStrArgFormat(
                pattern="^[\\s\\S]{0,1000}$",
            ),
        )
        _args_schema.destination_amw_accounts = AAZListArg(
            options=["--destination-amw-accounts", "--amw-accounts"],
            arg_group="Properties",
            help="Destination AMW accounts.",
        )
        _args_schema.enable_alert = AAZBoolArg(
            options=["--enable-alert"],
            arg_group="Properties",
            help="A flag to determine whether alert is enabled.",
        )
        _args_schema.evaluation_type = AAZStrArg(
            options=["--evaluation-type"],
            arg_group="Properties",
            help="Determines how the SLI is evaluated—either based on request counts or time windows.",
            enum={"RequestBased": "RequestBased", "WindowBased": "WindowBased"},
        )
        _args_schema.sli_properties = AAZObjectArg(
            options=["--sli-properties"],
            arg_group="Properties",
            help="Defines the SLI properties associated with the SLI.",
        )

        baseline_properties = cls._args_schema.baseline_properties
        baseline_properties.baseline = AAZObjectArg(
            options=["baseline"],
            help="Defines the baseline target, which is compared against the SLI value to determine compliance.",
        )

        baseline = cls._args_schema.baseline_properties.baseline
        baseline.evaluation_calculation_type = AAZStrArg(
            options=["evaluation-calculation-type"],
            help="Specifies how evaluation is calculated, either based on calendar days or a rolling window.",
            enum={"CalendarDays": "CalendarDays", "RollingDays": "RollingDays"},
        )
        baseline.evaluation_period_days = AAZIntArg(
            options=["evaluation-period-days"],
            help="The time frame (in days) used for SLI evaluation.",
            fmt=AAZIntArgFormat(
                maximum=90,
                minimum=1,
            ),
        )
        baseline.value = AAZFloatArg(
            options=["value"],
            help="The user-defined or Azure-defined target value used for comparison against the SLI value.",
            fmt=AAZFloatArgFormat(
                maximum=100.0,
                minimum=0.0,
            ),
        )

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

        _element = cls._args_schema.destination_amw_accounts.Element
        _element.identity = AAZResourceIdArg(
            options=["identity"],
            help="The ARM resource ID of the managed identity with access to the source account.",
        )
        _element.resource_id = AAZResourceIdArg(
            options=["resource-id"],
            help="The ARM resource ID of the account where metrics are emitted.",
        )

        sli_properties = cls._args_schema.sli_properties
        sli_properties.good_signals = AAZObjectArg(
            options=["good-signals"],
            help="Represents good signals used in request-based SLI calculations.",
            nullable=True,
        )
        cls._build_args_signal_update(sli_properties.good_signals)
        sli_properties.signals = AAZObjectArg(
            options=["signals"],
            help="Signals used for window-based SLI calculations.",
            nullable=True,
        )
        cls._build_args_signal_update(sli_properties.signals)
        sli_properties.total_signals = AAZObjectArg(
            options=["total-signals"],
            help="Represents total signals used in request-based SLI calculations.",
            nullable=True,
        )
        cls._build_args_signal_update(sli_properties.total_signals)
        sli_properties.window_uptime_criteria = AAZObjectArg(
            options=["window-uptime-criteria"],
            help="Defines the uptime criteria for window-based SLIs.",
            nullable=True,
        )

        window_uptime_criteria = cls._args_schema.sli_properties.window_uptime_criteria
        window_uptime_criteria.comparator = AAZStrArg(
            options=["comparator"],
            help="Comparison operator used for uptime evaluation.",
            enum={"gt": "gt", "gte": "gte", "lt": "lt", "lte": "lte"},
        )
        window_uptime_criteria.target = AAZFloatArg(
            options=["target"],
            help="Threshold value used to determine uptime.",
        )
        return cls._args_schema

    _args_signal_update = None

    @classmethod
    def _build_args_signal_update(cls, _schema):
        if cls._args_signal_update is not None:
            _schema.signal_formula = cls._args_signal_update.signal_formula
            _schema.signal_sources = cls._args_signal_update.signal_sources
            return

        cls._args_signal_update = AAZObjectArg(
            nullable=True,
        )

        signal_update = cls._args_signal_update
        signal_update.signal_formula = AAZStrArg(
            options=["signal-formula"],
            help="Mathematical formula used to combine multiple metrics.",
        )
        signal_update.signal_sources = AAZListArg(
            options=["signal-sources"],
            help="Sources of metrics used for SLIs.",
        )

        signal_sources = cls._args_signal_update.signal_sources
        signal_sources.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_signal_update.signal_sources.Element
        _element.filters = AAZListArg(
            options=["filters"],
            help="Filters applied to modify signal values.",
        )
        _element.metric_name = AAZStrArg(
            options=["metric-name"],
            help="Name of the metric.",
        )
        _element.metric_namespace = AAZStrArg(
            options=["metric-namespace"],
            help="Namespace of the metric.",
        )
        _element.signal_source_id = AAZStrArg(
            options=["signal-source-id"],
            help="Unique identifier for the signal source.",
        )
        _element.source_amw_account_managed_identity = AAZResourceIdArg(
            options=["source-amw-account-managed-identity"],
            help="Managed identity for authenticating the signal source.",
        )
        _element.source_amw_account_resource_id = AAZResourceIdArg(
            options=["source-amw-account-resource-id"],
            help="Resource ID of the source AMW account.",
        )
        _element.spatial_aggregation = AAZObjectArg(
            options=["spatial-aggregation"],
            help="Defines how measurements are aggregated across multiple time series.",
        )
        _element.temporal_aggregation = AAZObjectArg(
            options=["temporal-aggregation"],
            help="Defines how measurements are aggregated over a specific time window within the same time series.",
        )

        filters = cls._args_signal_update.signal_sources.Element.filters
        filters.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_signal_update.signal_sources.Element.filters.Element
        _element.dimension_name = AAZStrArg(
            options=["dimension-name"],
            help="Dimension name used in filtering.",
            nullable=True,
        )
        _element.operator = AAZStrArg(
            options=["operator"],
            help="Operator used in the filtering condition.",
            enum={"contains": "contains", "eq": "eq", "gt": "gt", "gte": "gte", "in": "in", "lt": "lt", "lte": "lte", "ne": "ne", "notcontains": "notcontains", "notin": "notin", "notstartswith": "notstartswith", "startswith": "startswith"},
        )
        _element.sampling_type = AAZStrArg(
            options=["sampling-type"],
            help="Defines the sampling type.",
            nullable=True,
            enum={"Average": "Average", "Count": "Count", "Max": "Max", "Min": "Min", "Sum": "Sum"},
        )
        _element.scalar_function = AAZStrArg(
            options=["scalar-function"],
            help="Scalar function applied for filtering.",
            nullable=True,
            enum={"avg": "avg", "max": "max", "min": "min", "sum": "sum"},
        )
        _element.value = AAZStrArg(
            options=["value"],
            help="Value used in filtering.",
        )

        spatial_aggregation = cls._args_signal_update.signal_sources.Element.spatial_aggregation
        spatial_aggregation.dimensions = AAZListArg(
            options=["dimensions"],
            help="Dimensions considered for spatial aggregation.",
        )
        spatial_aggregation.type = AAZStrArg(
            options=["type"],
            help="Type of spatial aggregation.",
            enum={"Average": "Average", "Count": "Count", "Max": "Max", "Min": "Min", "Sum": "Sum"},
        )

        dimensions = cls._args_signal_update.signal_sources.Element.spatial_aggregation.dimensions
        dimensions.Element = AAZStrArg(
            nullable=True,
        )

        temporal_aggregation = cls._args_signal_update.signal_sources.Element.temporal_aggregation
        temporal_aggregation.type = AAZStrArg(
            options=["type"],
            help="Type of temporal aggregation.",
            enum={"Average": "Average", "Delta": "Delta", "IDelta": "IDelta", "IRate": "IRate", "Increase": "Increase", "Max": "Max", "Min": "Min", "Rate": "Rate", "Sum": "Sum"},
        )
        temporal_aggregation.window_size_minutes = AAZIntArg(
            options=["window-size-minutes"],
            help="Time window size for aggregation, in minutes.",
            nullable=True,
        )

        _schema.signal_formula = cls._args_signal_update.signal_formula
        _schema.signal_sources = cls._args_signal_update.signal_sources

    def _execute_operations(self):
        self.pre_operations()
        self.SlisGet(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.SlisCreateOrUpdate(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 SlisGet(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(
                "/providers/Microsoft.Management/serviceGroups/{serviceGroupName}/providers/Microsoft.Monitor/slis/{sliName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "serviceGroupName", self.ctx.args.service_group_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "sliName", self.ctx.args.sli_name,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "api-version", "2025-03-01-preview",
                    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_sli_read(cls._schema_on_200)

            return cls._schema_on_200

    class SlisCreateOrUpdate(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(
                "/providers/Microsoft.Management/serviceGroups/{serviceGroupName}/providers/Microsoft.Monitor/slis/{sliName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "serviceGroupName", self.ctx.args.service_group_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "sliName", self.ctx.args.sli_name,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "api-version", "2025-03-01-preview",
                    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_sli_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("identity", AAZIdentityObjectType)
            _builder.set_prop("properties", AAZObjectType)

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("baselineProperties", AAZObjectType, ".baseline_properties", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("category", AAZStrType, ".category", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("description", AAZStrType, ".description", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("destinationAmwAccounts", AAZListType, ".destination_amw_accounts", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("enableAlert", AAZBoolType, ".enable_alert", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("evaluationType", AAZStrType, ".evaluation_type", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("sliProperties", AAZObjectType, ".sli_properties", typ_kwargs={"flags": {"required": True}})

            baseline_properties = _builder.get(".properties.baselineProperties")
            if baseline_properties is not None:
                baseline_properties.set_prop("baseline", AAZObjectType, ".baseline", typ_kwargs={"flags": {"required": True}})

            baseline = _builder.get(".properties.baselineProperties.baseline")
            if baseline is not None:
                baseline.set_prop("evaluationCalculationType", AAZStrType, ".evaluation_calculation_type", typ_kwargs={"flags": {"required": True}})
                baseline.set_prop("evaluationPeriodDays", AAZIntType, ".evaluation_period_days", typ_kwargs={"flags": {"required": True}})
                baseline.set_prop("value", AAZFloatType, ".value", typ_kwargs={"flags": {"required": True}})

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

            _elements = _builder.get(".properties.destinationAmwAccounts[]")
            if _elements is not None:
                _elements.set_prop("identity", AAZStrType, ".identity", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("resourceId", AAZStrType, ".resource_id", typ_kwargs={"flags": {"required": True}})

            sli_properties = _builder.get(".properties.sliProperties")
            if sli_properties is not None:
                _UpdateHelper._build_schema_signal_update(sli_properties.set_prop("goodSignals", AAZObjectType, ".good_signals"))
                _UpdateHelper._build_schema_signal_update(sli_properties.set_prop("signals", AAZObjectType, ".signals"))
                _UpdateHelper._build_schema_signal_update(sli_properties.set_prop("totalSignals", AAZObjectType, ".total_signals"))
                sli_properties.set_prop("windowUptimeCriteria", AAZObjectType, ".window_uptime_criteria")

            window_uptime_criteria = _builder.get(".properties.sliProperties.windowUptimeCriteria")
            if window_uptime_criteria is not None:
                window_uptime_criteria.set_prop("comparator", AAZStrType, ".comparator", typ_kwargs={"flags": {"required": True}})
                window_uptime_criteria.set_prop("target", AAZFloatType, ".target", typ_kwargs={"flags": {"required": True}})

            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"""

    @classmethod
    def _build_schema_signal_update(cls, _builder):
        if _builder is None:
            return
        _builder.set_prop("signalFormula", AAZStrType, ".signal_formula", typ_kwargs={"flags": {"required": True}})
        _builder.set_prop("signalSources", AAZListType, ".signal_sources", typ_kwargs={"flags": {"required": True}})

        signal_sources = _builder.get(".signalSources")
        if signal_sources is not None:
            signal_sources.set_elements(AAZObjectType, ".")

        _elements = _builder.get(".signalSources[]")
        if _elements is not None:
            _elements.set_prop("filters", AAZListType, ".filters", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("metricName", AAZStrType, ".metric_name", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("metricNamespace", AAZStrType, ".metric_namespace", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("signalSourceId", AAZStrType, ".signal_source_id", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("sourceAmwAccountManagedIdentity", AAZStrType, ".source_amw_account_managed_identity", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("sourceAmwAccountResourceId", AAZStrType, ".source_amw_account_resource_id", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("spatialAggregation", AAZObjectType, ".spatial_aggregation", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("temporalAggregation", AAZObjectType, ".temporal_aggregation", typ_kwargs={"flags": {"required": True}})

        filters = _builder.get(".signalSources[].filters")
        if filters is not None:
            filters.set_elements(AAZObjectType, ".")

        _elements = _builder.get(".signalSources[].filters[]")
        if _elements is not None:
            _elements.set_prop("dimensionName", AAZStrType, ".dimension_name")
            _elements.set_prop("operator", AAZStrType, ".operator", typ_kwargs={"flags": {"required": True}})
            _elements.set_prop("samplingType", AAZStrType, ".sampling_type")
            _elements.set_prop("scalarFunction", AAZStrType, ".scalar_function")
            _elements.set_prop("value", AAZStrType, ".value", typ_kwargs={"flags": {"required": True}})

        spatial_aggregation = _builder.get(".signalSources[].spatialAggregation")
        if spatial_aggregation is not None:
            spatial_aggregation.set_prop("dimensions", AAZListType, ".dimensions", typ_kwargs={"flags": {"required": True}})
            spatial_aggregation.set_prop("type", AAZStrType, ".type", typ_kwargs={"flags": {"required": True}})

        dimensions = _builder.get(".signalSources[].spatialAggregation.dimensions")
        if dimensions is not None:
            dimensions.set_elements(AAZStrType, ".")

        temporal_aggregation = _builder.get(".signalSources[].temporalAggregation")
        if temporal_aggregation is not None:
            temporal_aggregation.set_prop("type", AAZStrType, ".type", typ_kwargs={"flags": {"required": True}})
            temporal_aggregation.set_prop("windowSizeMinutes", AAZIntType, ".window_size_minutes")

    _schema_signal_read = None

    @classmethod
    def _build_schema_signal_read(cls, _schema):
        if cls._schema_signal_read is not None:
            _schema.signal_formula = cls._schema_signal_read.signal_formula
            _schema.signal_sources = cls._schema_signal_read.signal_sources
            return

        cls._schema_signal_read = _schema_signal_read = AAZObjectType()

        signal_read = _schema_signal_read
        signal_read.signal_formula = AAZStrType(
            serialized_name="signalFormula",
            flags={"required": True},
        )
        signal_read.signal_sources = AAZListType(
            serialized_name="signalSources",
            flags={"required": True},
        )

        signal_sources = _schema_signal_read.signal_sources
        signal_sources.Element = AAZObjectType()

        _element = _schema_signal_read.signal_sources.Element
        _element.filters = AAZListType(
            flags={"required": True},
        )
        _element.metric_name = AAZStrType(
            serialized_name="metricName",
            flags={"required": True},
        )
        _element.metric_namespace = AAZStrType(
            serialized_name="metricNamespace",
            flags={"required": True},
        )
        _element.signal_source_id = AAZStrType(
            serialized_name="signalSourceId",
            flags={"required": True},
        )
        _element.source_amw_account_managed_identity = AAZStrType(
            serialized_name="sourceAmwAccountManagedIdentity",
            flags={"required": True},
        )
        _element.source_amw_account_resource_id = AAZStrType(
            serialized_name="sourceAmwAccountResourceId",
            flags={"required": True},
        )
        _element.spatial_aggregation = AAZObjectType(
            serialized_name="spatialAggregation",
            flags={"required": True},
        )
        _element.temporal_aggregation = AAZObjectType(
            serialized_name="temporalAggregation",
            flags={"required": True},
        )

        filters = _schema_signal_read.signal_sources.Element.filters
        filters.Element = AAZObjectType()

        _element = _schema_signal_read.signal_sources.Element.filters.Element
        _element.dimension_name = AAZStrType(
            serialized_name="dimensionName",
        )
        _element.operator = AAZStrType(
            flags={"required": True},
        )
        _element.sampling_type = AAZStrType(
            serialized_name="samplingType",
        )
        _element.scalar_function = AAZStrType(
            serialized_name="scalarFunction",
        )
        _element.value = AAZStrType(
            flags={"required": True},
        )

        spatial_aggregation = _schema_signal_read.signal_sources.Element.spatial_aggregation
        spatial_aggregation.dimensions = AAZListType(
            flags={"required": True},
        )
        spatial_aggregation.type = AAZStrType(
            flags={"required": True},
        )

        dimensions = _schema_signal_read.signal_sources.Element.spatial_aggregation.dimensions
        dimensions.Element = AAZStrType()

        temporal_aggregation = _schema_signal_read.signal_sources.Element.temporal_aggregation
        temporal_aggregation.type = AAZStrType(
            flags={"required": True},
        )
        temporal_aggregation.window_size_minutes = AAZIntType(
            serialized_name="windowSizeMinutes",
        )

        _schema.signal_formula = cls._schema_signal_read.signal_formula
        _schema.signal_sources = cls._schema_signal_read.signal_sources

    _schema_sli_read = None

    @classmethod
    def _build_schema_sli_read(cls, _schema):
        if cls._schema_sli_read is not None:
            _schema.id = cls._schema_sli_read.id
            _schema.identity = cls._schema_sli_read.identity
            _schema.name = cls._schema_sli_read.name
            _schema.properties = cls._schema_sli_read.properties
            _schema.system_data = cls._schema_sli_read.system_data
            _schema.type = cls._schema_sli_read.type
            return

        cls._schema_sli_read = _schema_sli_read = AAZObjectType()

        sli_read = _schema_sli_read
        sli_read.id = AAZStrType(
            flags={"read_only": True},
        )
        sli_read.identity = AAZIdentityObjectType()
        sli_read.name = AAZStrType(
            flags={"read_only": True},
        )
        sli_read.properties = AAZObjectType()
        sli_read.system_data = AAZObjectType(
            serialized_name="systemData",
            flags={"read_only": True},
        )
        sli_read.type = AAZStrType(
            flags={"read_only": True},
        )

        identity = _schema_sli_read.identity
        identity.principal_id = AAZStrType(
            serialized_name="principalId",
            flags={"read_only": True},
        )
        identity.tenant_id = AAZStrType(
            serialized_name="tenantId",
            flags={"read_only": True},
        )
        identity.type = AAZStrType(
            flags={"required": True},
        )
        identity.user_assigned_identities = AAZDictType(
            serialized_name="userAssignedIdentities",
        )

        user_assigned_identities = _schema_sli_read.identity.user_assigned_identities
        user_assigned_identities.Element = AAZObjectType(
            nullable=True,
        )

        _element = _schema_sli_read.identity.user_assigned_identities.Element
        _element.client_id = AAZStrType(
            serialized_name="clientId",
            flags={"read_only": True},
        )
        _element.principal_id = AAZStrType(
            serialized_name="principalId",
            flags={"read_only": True},
        )

        properties = _schema_sli_read.properties
        properties.baseline_properties = AAZObjectType(
            serialized_name="baselineProperties",
            flags={"required": True},
        )
        properties.category = AAZStrType(
            flags={"required": True},
        )
        properties.description = AAZStrType(
            flags={"required": True},
        )
        properties.destination_amw_accounts = AAZListType(
            serialized_name="destinationAmwAccounts",
            flags={"required": True},
        )
        properties.destination_metrics = AAZListType(
            serialized_name="destinationMetrics",
            flags={"read_only": True},
        )
        properties.enable_alert = AAZBoolType(
            serialized_name="enableAlert",
            flags={"required": True},
        )
        properties.evaluation_type = AAZStrType(
            serialized_name="evaluationType",
            flags={"required": True},
        )
        properties.execution_state = AAZObjectType(
            serialized_name="executionState",
            flags={"read_only": True},
        )
        properties.provisioning_state = AAZStrType(
            serialized_name="provisioningState",
            flags={"read_only": True},
        )
        properties.sli_properties = AAZObjectType(
            serialized_name="sliProperties",
            flags={"required": True},
        )
        properties.streaming_rule_id = AAZStrType(
            serialized_name="streamingRuleId",
            flags={"read_only": True},
        )
        properties.streaming_rule_last_updated_timestamp = AAZStrType(
            serialized_name="streamingRuleLastUpdatedTimestamp",
            flags={"read_only": True},
        )

        baseline_properties = _schema_sli_read.properties.baseline_properties
        baseline_properties.baseline = AAZObjectType(
            flags={"required": True},
        )

        baseline = _schema_sli_read.properties.baseline_properties.baseline
        baseline.evaluation_calculation_type = AAZStrType(
            serialized_name="evaluationCalculationType",
            flags={"required": True},
        )
        baseline.evaluation_period_days = AAZIntType(
            serialized_name="evaluationPeriodDays",
            flags={"required": True},
        )
        baseline.value = AAZFloatType(
            flags={"required": True},
        )

        destination_amw_accounts = _schema_sli_read.properties.destination_amw_accounts
        destination_amw_accounts.Element = AAZObjectType()

        _element = _schema_sli_read.properties.destination_amw_accounts.Element
        _element.identity = AAZStrType(
            flags={"required": True},
        )
        _element.resource_id = AAZStrType(
            serialized_name="resourceId",
            flags={"required": True},
        )

        destination_metrics = _schema_sli_read.properties.destination_metrics
        destination_metrics.Element = AAZObjectType()

        _element = _schema_sli_read.properties.destination_metrics.Element
        _element.metric_name = AAZStrType(
            serialized_name="metricName",
            flags={"required": True},
        )
        _element.metric_namespace = AAZStrType(
            serialized_name="metricNamespace",
            flags={"required": True},
        )

        execution_state = _schema_sli_read.properties.execution_state
        execution_state.message = AAZStrType()
        execution_state.state = AAZStrType(
            flags={"required": True},
        )

        sli_properties = _schema_sli_read.properties.sli_properties
        sli_properties.good_signals = AAZObjectType(
            serialized_name="goodSignals",
        )
        cls._build_schema_signal_read(sli_properties.good_signals)
        sli_properties.signals = AAZObjectType()
        cls._build_schema_signal_read(sli_properties.signals)
        sli_properties.total_signals = AAZObjectType(
            serialized_name="totalSignals",
        )
        cls._build_schema_signal_read(sli_properties.total_signals)
        sli_properties.window_uptime_criteria = AAZObjectType(
            serialized_name="windowUptimeCriteria",
        )

        window_uptime_criteria = _schema_sli_read.properties.sli_properties.window_uptime_criteria
        window_uptime_criteria.comparator = AAZStrType(
            flags={"required": True},
        )
        window_uptime_criteria.target = AAZFloatType(
            flags={"required": True},
        )

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

        _schema.id = cls._schema_sli_read.id
        _schema.identity = cls._schema_sli_read.identity
        _schema.name = cls._schema_sli_read.name
        _schema.properties = cls._schema_sli_read.properties
        _schema.system_data = cls._schema_sli_read.system_data
        _schema.type = cls._schema_sli_read.type


__all__ = ["Update"]
