# --------------------------------------------------------------------------------------------
# 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 account issue show",
)
class Show(AAZCommand):
    """Get issue properties
    """

    _aaz_info = {
        "version": "2025-10-03",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.monitor/accounts/{}/issues/{}", "2025-10-03"],
        ]
    }

    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.azure_monitor_workspace_name = AAZStrArg(
            options=["-w", "--azure-monitor-workspace-name"],
            help="The name of the Azure Monitor Workspace. The name is case insensitive",
            required=True,
            id_part="name",
            fmt=AAZStrArgFormat(
                pattern="^(?!-)[a-zA-Z0-9-]+[^-]$",
            ),
        )
        _args_schema.issue_name = AAZStrArg(
            options=["-n", "--name", "--issue-name"],
            help="The name of the IssueResource",
            required=True,
            id_part="child_name_1",
            fmt=AAZStrArgFormat(
                pattern="^(?!-)[a-zA-Z0-9-]+[^-]$",
            ),
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.IssueGet(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 IssueGet(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.Monitor/accounts/{azureMonitorWorkspaceName}/issues/{issueName}",
                **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(
                    "azureMonitorWorkspaceName", self.ctx.args.azure_monitor_workspace_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "issueName", self.ctx.args.issue_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", "2025-10-03",
                    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.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},
            )

            properties = cls._schema_on_200.properties
            properties.background = AAZObjectType()
            properties.impact_time = AAZStrType(
                serialized_name="impactTime",
                flags={"required": True},
            )
            properties.investigations = AAZListType(
                flags={"read_only": True},
            )
            properties.investigations_count = AAZIntType(
                serialized_name="investigationsCount",
                flags={"read_only": True},
            )
            properties.notifications = AAZObjectType()
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
                flags={"read_only": True},
            )
            properties.severity = AAZStrType(
                flags={"required": True},
            )
            properties.status = AAZStrType(
                flags={"required": True},
            )
            properties.title = AAZStrType(
                flags={"required": True},
            )

            background = cls._schema_on_200.properties.background
            background.details = AAZListType()
            background.text = AAZStrType()
            background.type = AAZStrType()

            details = cls._schema_on_200.properties.background.details
            details.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.background.details.Element
            _element.name = AAZStrType(
                flags={"required": True},
            )
            _element.value = AAZStrType(
                flags={"required": True},
            )

            investigations = cls._schema_on_200.properties.investigations
            investigations.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.investigations.Element
            _element.created_at = AAZStrType(
                serialized_name="createdAt",
                flags={"required": True},
            )
            _element.id = AAZStrType(
                flags={"required": True},
            )

            notifications = cls._schema_on_200.properties.notifications
            notifications.action_group_ids = AAZListType(
                serialized_name="actionGroupIds",
            )
            notifications.exclude_default_action_groups = AAZBoolType(
                serialized_name="excludeDefaultActionGroups",
            )
            notifications.update_types = AAZListType(
                serialized_name="updateTypes",
            )

            action_group_ids = cls._schema_on_200.properties.notifications.action_group_ids
            action_group_ids.Element = AAZStrType()

            update_types = cls._schema_on_200.properties.notifications.update_types
            update_types.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.notifications.update_types.Element
            _element.update_type = AAZStrType(
                serialized_name="updateType",
                flags={"required": True},
            )

            disc_time_based = cls._schema_on_200.properties.notifications.update_types.Element.discriminate_by("update_type", "TimeBased")
            disc_time_based.update_interval = AAZStrType(
                serialized_name="updateInterval",
                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"""


__all__ = ["Show"]
