# --------------------------------------------------------------------------------------------
# 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 entity-query list",
    is_experimental=True,
)
class List(AAZCommand):
    """Get all entity queries.
    """

    _aaz_info = {
        "version": "2022-06-01-preview",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.operationalinsights/workspaces/{}/providers/microsoft.securityinsights/entityqueries", "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.kind = AAZStrArg(
            options=["--kind"],
            help="The entity query kind we want to fetch",
            enum={"Activity": "Activity", "Expansion": "Expansion"},
        )
        return cls._args_schema

    def _execute_operations(self):
        self.EntityQueriesList(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 EntityQueriesList(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/entityQueries",
                **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(
                    "kind", self.ctx.args.kind,
                ),
                **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.kind = AAZStrType(
                flags={"required": True},
            )
            _element.name = AAZStrType(
                flags={"read_only": True},
            )
            _element.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _element.type = AAZStrType(
                flags={"read_only": True},
            )

            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},
            )

            disc_activity = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity")
            disc_activity.properties = AAZObjectType(
                flags={"client_flatten": True},
            )

            properties = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties
            properties.content = AAZStrType()
            properties.created_time_utc = AAZStrType(
                serialized_name="createdTimeUtc",
                flags={"read_only": True},
            )
            properties.description = AAZStrType()
            properties.enabled = AAZBoolType()
            properties.entities_filter = AAZDictType(
                serialized_name="entitiesFilter",
            )
            properties.input_entity_type = AAZStrType(
                serialized_name="inputEntityType",
            )
            properties.last_modified_time_utc = AAZStrType(
                serialized_name="lastModifiedTimeUtc",
                flags={"read_only": True},
            )
            properties.query_definitions = AAZObjectType(
                serialized_name="queryDefinitions",
            )
            properties.required_input_fields_sets = AAZListType(
                serialized_name="requiredInputFieldsSets",
            )
            properties.template_name = AAZStrType(
                serialized_name="templateName",
            )
            properties.title = AAZStrType()

            entities_filter = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties.entities_filter
            entities_filter.Element = AAZListType()

            _element = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties.entities_filter.Element
            _element.Element = AAZStrType()

            query_definitions = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties.query_definitions
            query_definitions.query = AAZStrType()

            required_input_fields_sets = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties.required_input_fields_sets
            required_input_fields_sets.Element = AAZListType()

            _element = cls._schema_on_200.value.Element.discriminate_by("kind", "Activity").properties.required_input_fields_sets.Element
            _element.Element = AAZStrType()

            disc_expansion = cls._schema_on_200.value.Element.discriminate_by("kind", "Expansion")
            disc_expansion.properties = AAZObjectType(
                flags={"client_flatten": True},
            )

            properties = cls._schema_on_200.value.Element.discriminate_by("kind", "Expansion").properties
            properties.data_sources = AAZListType(
                serialized_name="dataSources",
            )
            properties.display_name = AAZStrType(
                serialized_name="displayName",
            )
            properties.input_entity_type = AAZStrType(
                serialized_name="inputEntityType",
            )
            properties.input_fields = AAZListType(
                serialized_name="inputFields",
            )
            properties.output_entity_types = AAZListType(
                serialized_name="outputEntityTypes",
            )
            properties.query_template = AAZStrType(
                serialized_name="queryTemplate",
            )

            data_sources = cls._schema_on_200.value.Element.discriminate_by("kind", "Expansion").properties.data_sources
            data_sources.Element = AAZStrType()

            input_fields = cls._schema_on_200.value.Element.discriminate_by("kind", "Expansion").properties.input_fields
            input_fields.Element = AAZStrType()

            output_entity_types = cls._schema_on_200.value.Element.discriminate_by("kind", "Expansion").properties.output_entity_types
            output_entity_types.Element = AAZStrType()

            return cls._schema_on_200


__all__ = ["List"]
