# --------------------------------------------------------------------------------------------
# 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 update",
    is_experimental=True,
)
class Update(AAZCommand):
    """Update a threat Intelligence indicator.
    """

    _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",
        )

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.confidence = AAZIntArg(
            options=["--confidence"],
            arg_group="Properties",
            help="Confidence of threat intelligence entity",
        )
        _args_schema.created = AAZStrArg(
            options=["--created"],
            arg_group="Properties",
            help="Created by",
        )
        _args_schema.created_by_ref = AAZStrArg(
            options=["--created-by-ref"],
            arg_group="Properties",
            help="Created by reference of threat intelligence entity",
        )
        _args_schema.defanged = AAZBoolArg(
            options=["--defanged"],
            arg_group="Properties",
            help="Is threat intelligence entity defanged",
        )
        _args_schema.description = AAZStrArg(
            options=["--description"],
            arg_group="Properties",
            help="Description of a threat intelligence entity",
        )
        _args_schema.display_name = AAZStrArg(
            options=["--display-name"],
            arg_group="Properties",
            help="Display name of a threat intelligence entity",
        )
        _args_schema.external_id = AAZStrArg(
            options=["--external-id"],
            arg_group="Properties",
            help="External ID of threat intelligence entity",
        )
        _args_schema.external_updated_time = AAZStrArg(
            options=["--external-updated-time"],
            arg_group="Properties",
            help="External last updated time in UTC",
        )
        _args_schema.external_references = AAZListArg(
            options=["--external-references"],
            arg_group="Properties",
            help="External References",
        )
        _args_schema.granular_markings = AAZListArg(
            options=["--granular-markings"],
            arg_group="Properties",
            help="Granular Markings",
        )
        _args_schema.indicator_types = AAZListArg(
            options=["--indicator-types"],
            arg_group="Properties",
            help="Indicator types of threat intelligence entities",
        )
        _args_schema.kill_chain_phases = AAZListArg(
            options=["--kill-chain-phases"],
            arg_group="Properties",
            help="Kill chain phases",
        )
        _args_schema.labels = AAZListArg(
            options=["--labels"],
            arg_group="Properties",
            help="Labels  of threat intelligence entity",
        )
        _args_schema.language = AAZStrArg(
            options=["--language"],
            arg_group="Properties",
            help="Language of threat intelligence entity",
        )
        _args_schema.last_updated_time = AAZStrArg(
            options=["--last-updated-time"],
            arg_group="Properties",
            help="Last updated time in UTC",
        )
        _args_schema.modified = AAZStrArg(
            options=["--modified"],
            arg_group="Properties",
            help="Modified by",
        )
        _args_schema.object_marking_refs = AAZListArg(
            options=["--object-marking-refs"],
            arg_group="Properties",
            help="Threat intelligence entity object marking references",
        )
        _args_schema.parsed_pattern = AAZListArg(
            options=["--parsed-pattern"],
            arg_group="Properties",
            help="Parsed patterns",
        )
        _args_schema.pattern = AAZStrArg(
            options=["--pattern"],
            arg_group="Properties",
            help="Pattern of a threat intelligence entity",
        )
        _args_schema.pattern_type = AAZStrArg(
            options=["--pattern-type"],
            arg_group="Properties",
            help="Pattern type of a threat intelligence entity",
        )
        _args_schema.pattern_version = AAZStrArg(
            options=["--pattern-version"],
            arg_group="Properties",
            help="Pattern version of a threat intelligence entity",
        )
        _args_schema.revoked = AAZBoolArg(
            options=["--revoked"],
            arg_group="Properties",
            help="Is threat intelligence entity revoked",
        )
        _args_schema.source = AAZStrArg(
            options=["--source"],
            arg_group="Properties",
            help="Source of a threat intelligence entity",
        )
        _args_schema.threat_tags = AAZListArg(
            options=["--threat-tags"],
            arg_group="Properties",
            help="List of tags",
        )
        _args_schema.threat_types = AAZListArg(
            options=["--threat-types"],
            arg_group="Properties",
            help="Threat types",
        )
        _args_schema.valid_from = AAZStrArg(
            options=["--valid-from"],
            arg_group="Properties",
            help="Valid from",
        )
        _args_schema.valid_until = AAZStrArg(
            options=["--valid-until"],
            arg_group="Properties",
            help="Valid until",
        )

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

        _element = cls._args_schema.external_references.Element
        _element.description = AAZStrArg(
            options=["description"],
            help="External reference description",
        )
        _element.external_id = AAZStrArg(
            options=["external-id"],
            help="External reference ID",
        )
        _element.hashes = AAZDictArg(
            options=["hashes"],
            help="External reference hashes",
        )
        _element.source_name = AAZStrArg(
            options=["source-name"],
            help="External reference source name",
        )
        _element.url = AAZStrArg(
            options=["url"],
            help="External reference URL",
        )

        hashes = cls._args_schema.external_references.Element.hashes
        hashes.Element = AAZStrArg()

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

        _element = cls._args_schema.granular_markings.Element
        _element.language = AAZStrArg(
            options=["language"],
            help="Language granular marking model",
        )
        _element.marking_ref = AAZIntArg(
            options=["marking-ref"],
            help="marking reference granular marking model",
        )
        _element.selectors = AAZListArg(
            options=["selectors"],
            help="granular marking model selectors",
        )

        selectors = cls._args_schema.granular_markings.Element.selectors
        selectors.Element = AAZStrArg()

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

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

        _element = cls._args_schema.kill_chain_phases.Element
        _element.kill_chain_name = AAZStrArg(
            options=["kill-chain-name"],
            help="Kill chainName name",
        )
        _element.phase_name = AAZStrArg(
            options=["phase-name"],
            help="Phase name",
        )

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

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

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

        _element = cls._args_schema.parsed_pattern.Element
        _element.pattern_type_key = AAZStrArg(
            options=["pattern-type-key"],
            help="Pattern type key",
        )
        _element.pattern_type_values = AAZListArg(
            options=["pattern-type-values"],
            help="Pattern type keys",
        )

        pattern_type_values = cls._args_schema.parsed_pattern.Element.pattern_type_values
        pattern_type_values.Element = AAZObjectArg()

        _element = cls._args_schema.parsed_pattern.Element.pattern_type_values.Element
        _element.value = AAZStrArg(
            options=["value"],
            help="Value of parsed pattern",
        )
        _element.value_type = AAZStrArg(
            options=["value-type"],
            help="Type of the value",
        )

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

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

        # define Arg Group "ThreatIntelligenceProperties"

        _args_schema = cls._args_schema
        _args_schema.etag = AAZStrArg(
            options=["--etag"],
            arg_group="ThreatIntelligenceProperties",
            help="Etag of the azure resource",
        )
        return cls._args_schema

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

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

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

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

        @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(
                    "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("etag", AAZStrType, ".etag")
            _builder.set_const("kind", "indicator", AAZStrType, ".", typ_kwargs={"flags": {"required": True}})
            _builder.set_prop("properties", AAZObjectType, typ_kwargs={"flags": {"client_flatten": True}})

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("confidence", AAZIntType, ".confidence")
                properties.set_prop("created", AAZStrType, ".created")
                properties.set_prop("createdByRef", AAZStrType, ".created_by_ref")
                properties.set_prop("defanged", AAZBoolType, ".defanged")
                properties.set_prop("description", AAZStrType, ".description")
                properties.set_prop("displayName", AAZStrType, ".display_name")
                properties.set_prop("externalId", AAZStrType, ".external_id")
                properties.set_prop("externalLastUpdatedTimeUtc", AAZStrType, ".external_updated_time")
                properties.set_prop("externalReferences", AAZListType, ".external_references")
                properties.set_prop("granularMarkings", AAZListType, ".granular_markings")
                properties.set_prop("indicatorTypes", AAZListType, ".indicator_types")
                properties.set_prop("killChainPhases", AAZListType, ".kill_chain_phases")
                properties.set_prop("labels", AAZListType, ".labels")
                properties.set_prop("language", AAZStrType, ".language")
                properties.set_prop("lastUpdatedTimeUtc", AAZStrType, ".last_updated_time")
                properties.set_prop("modified", AAZStrType, ".modified")
                properties.set_prop("objectMarkingRefs", AAZListType, ".object_marking_refs")
                properties.set_prop("parsedPattern", AAZListType, ".parsed_pattern")
                properties.set_prop("pattern", AAZStrType, ".pattern")
                properties.set_prop("patternType", AAZStrType, ".pattern_type")
                properties.set_prop("patternVersion", AAZStrType, ".pattern_version")
                properties.set_prop("revoked", AAZBoolType, ".revoked")
                properties.set_prop("source", AAZStrType, ".source")
                properties.set_prop("threatIntelligenceTags", AAZListType, ".threat_tags")
                properties.set_prop("threatTypes", AAZListType, ".threat_types")
                properties.set_prop("validFrom", AAZStrType, ".valid_from")
                properties.set_prop("validUntil", AAZStrType, ".valid_until")

            external_references = _builder.get(".properties.externalReferences")
            if external_references is not None:
                external_references.set_elements(AAZObjectType)

            _elements = _builder.get(".properties.externalReferences[]")
            if _elements is not None:
                _elements.set_prop("description", AAZStrType, ".description")
                _elements.set_prop("externalId", AAZStrType, ".external_id")
                _elements.set_prop("hashes", AAZDictType, ".hashes")
                _elements.set_prop("sourceName", AAZStrType, ".source_name")
                _elements.set_prop("url", AAZStrType, ".url")

            hashes = _builder.get(".properties.externalReferences[].hashes")
            if hashes is not None:
                hashes.set_elements(AAZStrType, ".")

            granular_markings = _builder.get(".properties.granularMarkings")
            if granular_markings is not None:
                granular_markings.set_elements(AAZObjectType)

            _elements = _builder.get(".properties.granularMarkings[]")
            if _elements is not None:
                _elements.set_prop("language", AAZStrType, ".language")
                _elements.set_prop("markingRef", AAZIntType, ".marking_ref")
                _elements.set_prop("selectors", AAZListType, ".selectors")

            selectors = _builder.get(".properties.granularMarkings[].selectors")
            if selectors is not None:
                selectors.set_elements(AAZStrType, ".")

            indicator_types = _builder.get(".properties.indicatorTypes")
            if indicator_types is not None:
                indicator_types.set_elements(AAZStrType, ".")

            kill_chain_phases = _builder.get(".properties.killChainPhases")
            if kill_chain_phases is not None:
                kill_chain_phases.set_elements(AAZObjectType)

            _elements = _builder.get(".properties.killChainPhases[]")
            if _elements is not None:
                _elements.set_prop("killChainName", AAZStrType, ".kill_chain_name")
                _elements.set_prop("phaseName", AAZStrType, ".phase_name")

            labels = _builder.get(".properties.labels")
            if labels is not None:
                labels.set_elements(AAZStrType, ".")

            object_marking_refs = _builder.get(".properties.objectMarkingRefs")
            if object_marking_refs is not None:
                object_marking_refs.set_elements(AAZStrType, ".")

            parsed_pattern = _builder.get(".properties.parsedPattern")
            if parsed_pattern is not None:
                parsed_pattern.set_elements(AAZObjectType)

            _elements = _builder.get(".properties.parsedPattern[]")
            if _elements is not None:
                _elements.set_prop("patternTypeKey", AAZStrType, ".pattern_type_key")
                _elements.set_prop("patternTypeValues", AAZListType, ".pattern_type_values")

            pattern_type_values = _builder.get(".properties.parsedPattern[].patternTypeValues")
            if pattern_type_values is not None:
                pattern_type_values.set_elements(AAZObjectType)

            _elements = _builder.get(".properties.parsedPattern[].patternTypeValues[]")
            if _elements is not None:
                _elements.set_prop("value", AAZStrType, ".value")
                _elements.set_prop("valueType", AAZStrType, ".value_type")

            threat_intelligence_tags = _builder.get(".properties.threatIntelligenceTags")
            if threat_intelligence_tags is not None:
                threat_intelligence_tags.set_elements(AAZStrType, ".")

            threat_types = _builder.get(".properties.threatTypes")
            if threat_types is not None:
                threat_types.set_elements(AAZStrType, ".")

            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.etag = AAZStrType()
            _schema_on_200_201.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.kind = AAZStrType(
                flags={"required": True},
            )
            _schema_on_200_201.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _schema_on_200_201.type = AAZStrType(
                flags={"read_only": True},
            )

            system_data = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator")
            disc_indicator.properties = AAZObjectType(
                flags={"client_flatten": True},
            )

            properties = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.external_references
            external_references.Element = AAZObjectType()

            _element = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.external_references.Element.hashes
            hashes.Element = AAZStrType()

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

            _element = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.granular_markings.Element.selectors
            selectors.Element = AAZStrType()

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

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

            _element = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.labels
            labels.Element = AAZStrType()

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

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

            _element = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.parsed_pattern.Element.pattern_type_values
            pattern_type_values.Element = AAZObjectType()

            _element = cls._schema_on_200_201.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_201.discriminate_by("kind", "indicator").properties.threat_intelligence_tags
            threat_intelligence_tags.Element = AAZStrType()

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

            return cls._schema_on_200_201


__all__ = ["Update"]
