# --------------------------------------------------------------------------------------------
# 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(
    "networkcloud kubernetescluster agentpool list",
)
class List(AAZCommand):
    """List agent pools for the provided Kubernetes cluster.

    :example: List agent pools of the Kubernetes cluster
        az networkcloud kubernetescluster agentpool list --kubernetes-cluster-name "kubernetesClusterName" --resource-group "resourceGroupName"
    """

    _aaz_info = {
        "version": "2023-07-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.networkcloud/kubernetesclusters/{}/agentpools", "2023-07-01"],
        ]
    }

    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.kubernetes_cluster_name = AAZStrArg(
            options=["--kubernetes-cluster-name"],
            help="The name of the Kubernetes cluster.",
            required=True,
            fmt=AAZStrArgFormat(
                pattern="^([a-zA-Z0-9][a-zA-Z0-9-_]{0,28}[a-zA-Z0-9])$",
            ),
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.AgentPoolsListByKubernetesCluster(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.value, client_flatten=True)
        next_link = self.deserialize_output(self.ctx.vars.instance.next_link)
        return result, next_link

    class AgentPoolsListByKubernetesCluster(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.NetworkCloud/kubernetesClusters/{kubernetesClusterName}/agentPools",
                **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(
                    "kubernetesClusterName", self.ctx.args.kubernetes_cluster_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", "2023-07-01",
                    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",
            )
            _schema_on_200.value = AAZListType()

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

            _element = cls._schema_on_200.value.Element
            _element.extended_location = AAZObjectType(
                serialized_name="extendedLocation",
            )
            _element.id = AAZStrType(
                flags={"read_only": True},
            )
            _element.location = AAZStrType(
                flags={"required": True},
            )
            _element.name = AAZStrType(
                flags={"read_only": True},
            )
            _element.properties = AAZObjectType(
                flags={"required": True, "client_flatten": True},
            )
            _element.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _element.tags = AAZDictType()
            _element.type = AAZStrType(
                flags={"read_only": True},
            )

            extended_location = cls._schema_on_200.value.Element.extended_location
            extended_location.name = AAZStrType(
                flags={"required": True},
            )
            extended_location.type = AAZStrType(
                flags={"required": True},
            )

            properties = cls._schema_on_200.value.Element.properties
            properties.administrator_configuration = AAZObjectType(
                serialized_name="administratorConfiguration",
            )
            properties.agent_options = AAZObjectType(
                serialized_name="agentOptions",
            )
            properties.attached_network_configuration = AAZObjectType(
                serialized_name="attachedNetworkConfiguration",
            )
            properties.availability_zones = AAZListType(
                serialized_name="availabilityZones",
            )
            properties.count = AAZIntType(
                flags={"required": True},
            )
            properties.detailed_status = AAZStrType(
                serialized_name="detailedStatus",
                flags={"read_only": True},
            )
            properties.detailed_status_message = AAZStrType(
                serialized_name="detailedStatusMessage",
                flags={"read_only": True},
            )
            properties.kubernetes_version = AAZStrType(
                serialized_name="kubernetesVersion",
                flags={"read_only": True},
            )
            properties.labels = AAZListType()
            properties.mode = AAZStrType(
                flags={"required": True},
            )
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
                flags={"read_only": True},
            )
            properties.taints = AAZListType()
            properties.upgrade_settings = AAZObjectType(
                serialized_name="upgradeSettings",
            )
            properties.vm_sku_name = AAZStrType(
                serialized_name="vmSkuName",
                flags={"required": True},
            )

            administrator_configuration = cls._schema_on_200.value.Element.properties.administrator_configuration
            administrator_configuration.admin_username = AAZStrType(
                serialized_name="adminUsername",
            )
            administrator_configuration.ssh_public_keys = AAZListType(
                serialized_name="sshPublicKeys",
            )

            ssh_public_keys = cls._schema_on_200.value.Element.properties.administrator_configuration.ssh_public_keys
            ssh_public_keys.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.properties.administrator_configuration.ssh_public_keys.Element
            _element.key_data = AAZStrType(
                serialized_name="keyData",
                flags={"required": True},
            )

            agent_options = cls._schema_on_200.value.Element.properties.agent_options
            agent_options.hugepages_count = AAZIntType(
                serialized_name="hugepagesCount",
                flags={"required": True},
            )
            agent_options.hugepages_size = AAZStrType(
                serialized_name="hugepagesSize",
            )

            attached_network_configuration = cls._schema_on_200.value.Element.properties.attached_network_configuration
            attached_network_configuration.l2_networks = AAZListType(
                serialized_name="l2Networks",
            )
            attached_network_configuration.l3_networks = AAZListType(
                serialized_name="l3Networks",
            )
            attached_network_configuration.trunked_networks = AAZListType(
                serialized_name="trunkedNetworks",
            )

            l2_networks = cls._schema_on_200.value.Element.properties.attached_network_configuration.l2_networks
            l2_networks.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.properties.attached_network_configuration.l2_networks.Element
            _element.network_id = AAZStrType(
                serialized_name="networkId",
                flags={"required": True},
            )
            _element.plugin_type = AAZStrType(
                serialized_name="pluginType",
            )

            l3_networks = cls._schema_on_200.value.Element.properties.attached_network_configuration.l3_networks
            l3_networks.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.properties.attached_network_configuration.l3_networks.Element
            _element.ipam_enabled = AAZStrType(
                serialized_name="ipamEnabled",
            )
            _element.network_id = AAZStrType(
                serialized_name="networkId",
                flags={"required": True},
            )
            _element.plugin_type = AAZStrType(
                serialized_name="pluginType",
            )

            trunked_networks = cls._schema_on_200.value.Element.properties.attached_network_configuration.trunked_networks
            trunked_networks.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.properties.attached_network_configuration.trunked_networks.Element
            _element.network_id = AAZStrType(
                serialized_name="networkId",
                flags={"required": True},
            )
            _element.plugin_type = AAZStrType(
                serialized_name="pluginType",
            )

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

            labels = cls._schema_on_200.value.Element.properties.labels
            labels.Element = AAZObjectType()
            _ListHelper._build_schema_kubernetes_label_read(labels.Element)

            taints = cls._schema_on_200.value.Element.properties.taints
            taints.Element = AAZObjectType()
            _ListHelper._build_schema_kubernetes_label_read(taints.Element)

            upgrade_settings = cls._schema_on_200.value.Element.properties.upgrade_settings
            upgrade_settings.max_surge = AAZStrType(
                serialized_name="maxSurge",
            )

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

            tags = cls._schema_on_200.value.Element.tags
            tags.Element = AAZStrType()

            return cls._schema_on_200


class _ListHelper:
    """Helper class for List"""

    _schema_kubernetes_label_read = None

    @classmethod
    def _build_schema_kubernetes_label_read(cls, _schema):
        if cls._schema_kubernetes_label_read is not None:
            _schema.key = cls._schema_kubernetes_label_read.key
            _schema.value = cls._schema_kubernetes_label_read.value
            return

        cls._schema_kubernetes_label_read = _schema_kubernetes_label_read = AAZObjectType()

        kubernetes_label_read = _schema_kubernetes_label_read
        kubernetes_label_read.key = AAZStrType(
            flags={"required": True},
        )
        kubernetes_label_read.value = AAZStrType(
            flags={"required": True},
        )

        _schema.key = cls._schema_kubernetes_label_read.key
        _schema.value = cls._schema_kubernetes_label_read.value


__all__ = ["List"]
