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

    :example: Show an SLI by name.
        az monitor sli show --service-group-name MyServiceGroup --sli-name MySli
    """

    _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}$",
            ),
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.SlisGet(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 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()

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

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

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

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

            _element = cls._schema_on_200.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.properties.destination_metrics
            destination_metrics.Element = AAZObjectType()

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

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

            window_uptime_criteria = cls._schema_on_200.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.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


class _ShowHelper:
    """Helper class for Show"""

    _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__ = ["Show"]
