# --------------------------------------------------------------------------------------------
# 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(
    "sentinel threat-indicator show",
    is_experimental=True,
)
class Show(AAZCommand):
    """View a threat intelligence indicator by name.
    """

    _aaz_info = {
        "version": "2022-06-01-preview",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.operationalinsights/workspaces/{}/providers/microsoft.securityinsights/threatintelligence/main/indicators/{}", "2022-06-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.name = AAZStrArg(
            options=["-n", "--name"],
            help="Threat intelligence indicator name field.",
            required=True,
            id_part="child_name_2",
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.workspace_name = AAZStrArg(
            options=["-w", "--workspace-name"],
            help="The name of the workspace.",
            required=True,
            id_part="name",
        )
        return cls._args_schema

    def _execute_operations(self):
        self.ThreatIntelligenceIndicatorGet(ctx=self.ctx)()

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

    class ThreatIntelligenceIndicatorGet(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.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/{name}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "name", self.ctx.args.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,
                ),
                **self.serialize_url_param(
                    "workspaceName", self.ctx.args.workspace_name,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "api-version", "2022-06-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.etag = AAZStrType()
            _schema_on_200.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.kind = AAZStrType(
                flags={"required": True},
            )
            _schema_on_200.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _schema_on_200.type = AAZStrType(
                flags={"read_only": True},
            )

            system_data = cls._schema_on_200.system_data
            system_data.created_at = AAZStrType(
                serialized_name="createdAt",
                flags={"read_only": True},
            )
            system_data.created_by = AAZStrType(
                serialized_name="createdBy",
                flags={"read_only": True},
            )
            system_data.created_by_type = AAZStrType(
                serialized_name="createdByType",
                flags={"read_only": True},
            )
            system_data.last_modified_at = AAZStrType(
                serialized_name="lastModifiedAt",
                flags={"read_only": True},
            )
            system_data.last_modified_by = AAZStrType(
                serialized_name="lastModifiedBy",
                flags={"read_only": True},
            )
            system_data.last_modified_by_type = AAZStrType(
                serialized_name="lastModifiedByType",
                flags={"read_only": True},
            )

            disc_indicator = cls._schema_on_200.discriminate_by("kind", "indicator")
            disc_indicator.properties = AAZObjectType(
                flags={"client_flatten": True},
            )

            properties = cls._schema_on_200.discriminate_by("kind", "indicator").properties
            properties.additional_data = AAZDictType(
                serialized_name="additionalData",
                flags={"read_only": True},
            )
            properties.confidence = AAZIntType()
            properties.created = AAZStrType()
            properties.created_by_ref = AAZStrType(
                serialized_name="createdByRef",
            )
            properties.defanged = AAZBoolType()
            properties.description = AAZStrType()
            properties.display_name = AAZStrType(
                serialized_name="displayName",
            )
            properties.external_id = AAZStrType(
                serialized_name="externalId",
            )
            properties.external_last_updated_time_utc = AAZStrType(
                serialized_name="externalLastUpdatedTimeUtc",
            )
            properties.external_references = AAZListType(
                serialized_name="externalReferences",
            )
            properties.friendly_name = AAZStrType(
                serialized_name="friendlyName",
                flags={"read_only": True},
            )
            properties.granular_markings = AAZListType(
                serialized_name="granularMarkings",
            )
            properties.indicator_types = AAZListType(
                serialized_name="indicatorTypes",
            )
            properties.kill_chain_phases = AAZListType(
                serialized_name="killChainPhases",
            )
            properties.labels = AAZListType()
            properties.language = AAZStrType()
            properties.last_updated_time_utc = AAZStrType(
                serialized_name="lastUpdatedTimeUtc",
            )
            properties.modified = AAZStrType()
            properties.object_marking_refs = AAZListType(
                serialized_name="objectMarkingRefs",
            )
            properties.parsed_pattern = AAZListType(
                serialized_name="parsedPattern",
            )
            properties.pattern = AAZStrType()
            properties.pattern_type = AAZStrType(
                serialized_name="patternType",
            )
            properties.pattern_version = AAZStrType(
                serialized_name="patternVersion",
            )
            properties.revoked = AAZBoolType()
            properties.source = AAZStrType()
            properties.threat_intelligence_tags = AAZListType(
                serialized_name="threatIntelligenceTags",
            )
            properties.threat_types = AAZListType(
                serialized_name="threatTypes",
            )
            properties.valid_from = AAZStrType(
                serialized_name="validFrom",
            )
            properties.valid_until = AAZStrType(
                serialized_name="validUntil",
            )

            external_references = cls._schema_on_200.discriminate_by("kind", "indicator").properties.external_references
            external_references.Element = AAZObjectType()

            _element = cls._schema_on_200.discriminate_by("kind", "indicator").properties.external_references.Element
            _element.description = AAZStrType()
            _element.external_id = AAZStrType(
                serialized_name="externalId",
            )
            _element.hashes = AAZDictType()
            _element.source_name = AAZStrType(
                serialized_name="sourceName",
            )
            _element.url = AAZStrType()

            hashes = cls._schema_on_200.discriminate_by("kind", "indicator").properties.external_references.Element.hashes
            hashes.Element = AAZStrType()

            granular_markings = cls._schema_on_200.discriminate_by("kind", "indicator").properties.granular_markings
            granular_markings.Element = AAZObjectType()

            _element = cls._schema_on_200.discriminate_by("kind", "indicator").properties.granular_markings.Element
            _element.language = AAZStrType()
            _element.marking_ref = AAZIntType(
                serialized_name="markingRef",
            )
            _element.selectors = AAZListType()

            selectors = cls._schema_on_200.discriminate_by("kind", "indicator").properties.granular_markings.Element.selectors
            selectors.Element = AAZStrType()

            indicator_types = cls._schema_on_200.discriminate_by("kind", "indicator").properties.indicator_types
            indicator_types.Element = AAZStrType()

            kill_chain_phases = cls._schema_on_200.discriminate_by("kind", "indicator").properties.kill_chain_phases
            kill_chain_phases.Element = AAZObjectType()

            _element = cls._schema_on_200.discriminate_by("kind", "indicator").properties.kill_chain_phases.Element
            _element.kill_chain_name = AAZStrType(
                serialized_name="killChainName",
            )
            _element.phase_name = AAZStrType(
                serialized_name="phaseName",
            )

            labels = cls._schema_on_200.discriminate_by("kind", "indicator").properties.labels
            labels.Element = AAZStrType()

            object_marking_refs = cls._schema_on_200.discriminate_by("kind", "indicator").properties.object_marking_refs
            object_marking_refs.Element = AAZStrType()

            parsed_pattern = cls._schema_on_200.discriminate_by("kind", "indicator").properties.parsed_pattern
            parsed_pattern.Element = AAZObjectType()

            _element = cls._schema_on_200.discriminate_by("kind", "indicator").properties.parsed_pattern.Element
            _element.pattern_type_key = AAZStrType(
                serialized_name="patternTypeKey",
            )
            _element.pattern_type_values = AAZListType(
                serialized_name="patternTypeValues",
            )

            pattern_type_values = cls._schema_on_200.discriminate_by("kind", "indicator").properties.parsed_pattern.Element.pattern_type_values
            pattern_type_values.Element = AAZObjectType()

            _element = cls._schema_on_200.discriminate_by("kind", "indicator").properties.parsed_pattern.Element.pattern_type_values.Element
            _element.value = AAZStrType()
            _element.value_type = AAZStrType(
                serialized_name="valueType",
            )

            threat_intelligence_tags = cls._schema_on_200.discriminate_by("kind", "indicator").properties.threat_intelligence_tags
            threat_intelligence_tags.Element = AAZStrType()

            threat_types = cls._schema_on_200.discriminate_by("kind", "indicator").properties.threat_types
            threat_types.Element = AAZStrType()

            return cls._schema_on_200


__all__ = ["Show"]
