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

    A user-assigned managed identity is required and must match the identity
    referenced by each destination AMW account and each signal source. Complex
    object arguments (``--baseline-properties``, ``--destination-amw-accounts``,
    ``--sli-properties``) are easiest to pass via JSON files using the
    ``@filename.json`` syntax.

    :example: Create a window-based availability SLI from JSON payload files.
        az monitor sli create --service-group-name MyServiceGroup --sli-name MySli --user-assigned <uami-arm-id> --category Availability --evaluation-type WindowBased --description "API availability SLI" --baseline-properties @baseline.json --destination-amw-accounts @destinations.json --sli-properties @sli-properties.json
    """

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

    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"

        _args_schema = cls._args_schema
        _args_schema.mi_user_assigned = AAZListArg(
            options=["--user-assigned", "--mi-user-assigned"],
            arg_group="Identity",
            help="Set the user managed identities. At least one user-assigned managed identity is required; system-assigned identity is not supported by this service.",
            required=True,
            blank=[],
        )

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

        # 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.",
            required=True,
        )

        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.",
            required=True,
            enum={"CalendarDays": "CalendarDays", "RollingDays": "RollingDays"},
        )
        baseline.evaluation_period_days = AAZIntArg(
            options=["evaluation-period-days"],
            help="The time frame (in days) used for SLI evaluation.",
            required=True,
            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.",
            required=True,
            fmt=AAZFloatArgFormat(
                maximum=100.0,
                minimum=0.0,
            ),
        )

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

        _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.",
            required=True,
        )
        _element.resource_id = AAZResourceIdArg(
            options=["resource-id"],
            help="The ARM resource ID of the account where metrics are emitted.",
            required=True,
        )

        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.",
        )
        cls._build_args_signal_create(sli_properties.good_signals)
        sli_properties.signals = AAZObjectArg(
            options=["signals"],
            help="Signals used for window-based SLI calculations.",
        )
        cls._build_args_signal_create(sli_properties.signals)
        sli_properties.total_signals = AAZObjectArg(
            options=["total-signals"],
            help="Represents total signals used in request-based SLI calculations.",
        )
        cls._build_args_signal_create(sli_properties.total_signals)
        sli_properties.window_uptime_criteria = AAZObjectArg(
            options=["window-uptime-criteria"],
            help="Defines the uptime criteria for window-based SLIs.",
        )

        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.",
            required=True,
            enum={"gt": "gt", "gte": "gte", "lt": "lt", "lte": "lte"},
        )
        window_uptime_criteria.target = AAZFloatArg(
            options=["target"],
            help="Threshold value used to determine uptime.",
            required=True,
        )
        return cls._args_schema

    _args_signal_create = None

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

        cls._args_signal_create = AAZObjectArg()

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

        signal_sources = cls._args_signal_create.signal_sources
        signal_sources.Element = AAZObjectArg()

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

        filters = cls._args_signal_create.signal_sources.Element.filters
        filters.Element = AAZObjectArg()

        _element = cls._args_signal_create.signal_sources.Element.filters.Element
        _element.dimension_name = AAZStrArg(
            options=["dimension-name"],
            help="Dimension name used in filtering.",
        )
        _element.operator = AAZStrArg(
            options=["operator"],
            help="Operator used in the filtering condition.",
            required=True,
            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.",
            enum={"Average": "Average", "Count": "Count", "Max": "Max", "Min": "Min", "Sum": "Sum"},
        )
        _element.scalar_function = AAZStrArg(
            options=["scalar-function"],
            help="Scalar function applied for filtering.",
            enum={"avg": "avg", "max": "max", "min": "min", "sum": "sum"},
        )
        _element.value = AAZStrArg(
            options=["value"],
            help="Value used in filtering.",
            required=True,
        )

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

        dimensions = cls._args_signal_create.signal_sources.Element.spatial_aggregation.dimensions
        dimensions.Element = AAZStrArg()

        temporal_aggregation = cls._args_signal_create.signal_sources.Element.temporal_aggregation
        temporal_aggregation.type = AAZStrArg(
            options=["type"],
            help="Type of temporal aggregation.",
            required=True,
            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.",
        )

        _schema.signal_formula = cls._args_signal_create.signal_formula
        _schema.signal_sources = cls._args_signal_create.signal_sources

    def _execute_operations(self):
        self.pre_operations()
        self.SlisCreateOrUpdate(ctx=self.ctx)()
        self.post_operations()

    @register_callback
    def pre_operations(self):
        pass

    @register_callback
    def post_operations(self):
        pass

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

    class 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,
                typ=AAZObjectType,
                typ_kwargs={"flags": {"required": True, "client_flatten": True}}
            )
            _builder.set_prop("identity", AAZIdentityObjectType)
            _builder.set_prop("properties", AAZObjectType)

            identity = _builder.get(".identity")
            if identity is not None:
                identity.set_prop("userAssigned", AAZListType, ".mi_user_assigned", typ_kwargs={"flags": {"action": "create"}})

            user_assigned = _builder.get(".identity.userAssigned")
            if user_assigned is not None:
                user_assigned.set_elements(AAZStrType, ".")

            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:
                _CreateHelper._build_schema_signal_create(sli_properties.set_prop("goodSignals", AAZObjectType, ".good_signals"))
                _CreateHelper._build_schema_signal_create(sli_properties.set_prop("signals", AAZObjectType, ".signals"))
                _CreateHelper._build_schema_signal_create(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 self.serialize_content(_content_value)

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

        _schema_on_200_201 = None

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

            cls._schema_on_200_201 = AAZObjectType()

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

            identity = cls._schema_on_200_201.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 = cls._schema_on_200_201.identity.user_assigned_identities
            user_assigned_identities.Element = AAZObjectType(
                nullable=True,
            )

            _element = cls._schema_on_200_201.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 = cls._schema_on_200_201.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 = cls._schema_on_200_201.properties.baseline_properties
            baseline_properties.baseline = AAZObjectType(
                flags={"required": True},
            )

            baseline = cls._schema_on_200_201.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 = cls._schema_on_200_201.properties.destination_amw_accounts
            destination_amw_accounts.Element = AAZObjectType()

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

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

            _element = cls._schema_on_200_201.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 = cls._schema_on_200_201.properties.execution_state
            execution_state.message = AAZStrType()
            execution_state.state = AAZStrType(
                flags={"required": True},
            )

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

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

            system_data = cls._schema_on_200_201.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",
            )

            return cls._schema_on_200_201


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

    @classmethod
    def _build_schema_signal_create(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


__all__ = ["Create"]
