# --------------------------------------------------------------------------------------------
# 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 metadata list",
    is_experimental=True,
)
class List(AAZCommand):
    """List of all metadata
    """

    _aaz_info = {
        "version": "2022-06-01-preview",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.operationalinsights/workspaces/{}/providers/microsoft.securityinsights/metadata", "2022-06-01-preview"],
        ]
    }

    def _handler(self, command_args):
        super()._handler(command_args)
        return self.build_paging(self._execute_operations, 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.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.workspace_name = AAZStrArg(
            options=["-w", "--workspace-name"],
            help="The name of the workspace.",
            required=True,
            is_experimental=True,
        )
        _args_schema.filter = AAZStrArg(
            options=["--filter"],
            help="Filters the results, based on a Boolean condition. Optional.",
        )
        _args_schema.orderby = AAZStrArg(
            options=["--orderby"],
            help="Sorts the results. Optional.",
        )
        _args_schema.skip = AAZIntArg(
            options=["--skip"],
            help="Used to skip n elements in the OData query (offset). Returns a nextLink to the next page of results if there are any left.",
        )
        _args_schema.top = AAZIntArg(
            options=["--top"],
            help="Returns only the first n results. Optional.",
        )
        return cls._args_schema

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

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

    class MetadataList(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/metadata",
                **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(
                    "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(
                    "$filter", self.ctx.args.filter,
                ),
                **self.serialize_query_param(
                    "$orderby", self.ctx.args.orderby,
                ),
                **self.serialize_query_param(
                    "$skip", self.ctx.args.skip,
                ),
                **self.serialize_query_param(
                    "$top", self.ctx.args.top,
                ),
                **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.next_link = AAZStrType(
                serialized_name="nextLink",
                flags={"read_only": True},
            )
            _schema_on_200.value = AAZListType(
                flags={"required": True},
            )

            value = cls._schema_on_200.value
            value.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element
            _element.etag = AAZStrType()
            _element.id = AAZStrType(
                flags={"read_only": True},
            )
            _element.name = AAZStrType(
                flags={"read_only": True},
            )
            _element.properties = AAZObjectType(
                flags={"client_flatten": True},
            )
            _element.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _element.type = AAZStrType(
                flags={"read_only": True},
            )

            properties = cls._schema_on_200.value.Element.properties
            properties.author = AAZObjectType()
            properties.categories = AAZObjectType()
            properties.content_id = AAZStrType(
                serialized_name="contentId",
            )
            properties.content_schema_version = AAZStrType(
                serialized_name="contentSchemaVersion",
            )
            properties.custom_version = AAZStrType(
                serialized_name="customVersion",
            )
            properties.dependencies = AAZObjectType()
            _build_schema_metadata_dependencies_read(properties.dependencies)
            properties.first_publish_date = AAZStrType(
                serialized_name="firstPublishDate",
            )
            properties.icon = AAZStrType()
            properties.kind = AAZStrType(
                flags={"required": True},
            )
            properties.last_publish_date = AAZStrType(
                serialized_name="lastPublishDate",
            )
            properties.parent_id = AAZStrType(
                serialized_name="parentId",
                flags={"required": True},
            )
            properties.preview_images = AAZListType(
                serialized_name="previewImages",
            )
            properties.preview_images_dark = AAZListType(
                serialized_name="previewImagesDark",
            )
            properties.providers = AAZListType()
            properties.source = AAZObjectType()
            properties.support = AAZObjectType()
            properties.threat_analysis_tactics = AAZListType(
                serialized_name="threatAnalysisTactics",
            )
            properties.threat_analysis_techniques = AAZListType(
                serialized_name="threatAnalysisTechniques",
            )
            properties.version = AAZStrType()

            author = cls._schema_on_200.value.Element.properties.author
            author.email = AAZStrType()
            author.link = AAZStrType()
            author.name = AAZStrType()

            categories = cls._schema_on_200.value.Element.properties.categories
            categories.domains = AAZListType()
            categories.verticals = AAZListType()

            domains = cls._schema_on_200.value.Element.properties.categories.domains
            domains.Element = AAZStrType()

            verticals = cls._schema_on_200.value.Element.properties.categories.verticals
            verticals.Element = AAZStrType()

            preview_images = cls._schema_on_200.value.Element.properties.preview_images
            preview_images.Element = AAZStrType()

            preview_images_dark = cls._schema_on_200.value.Element.properties.preview_images_dark
            preview_images_dark.Element = AAZStrType()

            providers = cls._schema_on_200.value.Element.properties.providers
            providers.Element = AAZStrType()

            source = cls._schema_on_200.value.Element.properties.source
            source.kind = AAZStrType(
                flags={"required": True},
            )
            source.name = AAZStrType()
            source.source_id = AAZStrType(
                serialized_name="sourceId",
            )

            support = cls._schema_on_200.value.Element.properties.support
            support.email = AAZStrType()
            support.link = AAZStrType()
            support.name = AAZStrType()
            support.tier = AAZStrType(
                flags={"required": True},
            )

            threat_analysis_tactics = cls._schema_on_200.value.Element.properties.threat_analysis_tactics
            threat_analysis_tactics.Element = AAZStrType()

            threat_analysis_techniques = cls._schema_on_200.value.Element.properties.threat_analysis_techniques
            threat_analysis_techniques.Element = AAZStrType()

            system_data = cls._schema_on_200.value.Element.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},
            )

            return cls._schema_on_200


_schema_metadata_dependencies_read = None


def _build_schema_metadata_dependencies_read(_schema):
    global _schema_metadata_dependencies_read
    if _schema_metadata_dependencies_read is not None:
        _schema.content_id = _schema_metadata_dependencies_read.content_id
        _schema.criteria = _schema_metadata_dependencies_read.criteria
        _schema.kind = _schema_metadata_dependencies_read.kind
        _schema.name = _schema_metadata_dependencies_read.name
        _schema.operator = _schema_metadata_dependencies_read.operator
        _schema.version = _schema_metadata_dependencies_read.version
        return

    _schema_metadata_dependencies_read = AAZObjectType()

    metadata_dependencies_read = _schema_metadata_dependencies_read
    metadata_dependencies_read.content_id = AAZStrType(
        serialized_name="contentId",
    )
    metadata_dependencies_read.criteria = AAZListType()
    metadata_dependencies_read.kind = AAZStrType()
    metadata_dependencies_read.name = AAZStrType()
    metadata_dependencies_read.operator = AAZStrType()
    metadata_dependencies_read.version = AAZStrType()

    criteria = _schema_metadata_dependencies_read.criteria
    criteria.Element = AAZObjectType()
    _build_schema_metadata_dependencies_read(criteria.Element)

    _schema.content_id = _schema_metadata_dependencies_read.content_id
    _schema.criteria = _schema_metadata_dependencies_read.criteria
    _schema.kind = _schema_metadata_dependencies_read.kind
    _schema.name = _schema_metadata_dependencies_read.name
    _schema.operator = _schema_metadata_dependencies_read.operator
    _schema.version = _schema_metadata_dependencies_read.version


__all__ = ["List"]
