# --------------------------------------------------------------------------------------------
# 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(
    "qumulo storage file-system create",
)
class Create(AAZCommand):
    """Create file system resource

    :example: Create file system
        az qumulo storage file-system create -n sys_name -g rg --admin-password testadmin --delegated-subnet-id subnet-id --initial-capacity 50 --marketplace-details "{offerId:qumulo-saas-mpp,planId:qumulo-on-azure-v1%%gmz7xq9ge3py%%P1M,publisherId:qumulo1584033880660}" --storage-sku Standard --user-details "{email:test@test.com}" --availability-zone 1
    """

    _aaz_info = {
        "version": "2022-10-12",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/qumulo.storage/filesystems/{}", "2022-10-12"],
        ]
    }

    AZ_SUPPORT_NO_WAIT = True

    def _handler(self, command_args):
        super()._handler(command_args)
        return self.build_lro_poller(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.file_system_name = AAZStrArg(
            options=["-n", "--name", "--file-system-name"],
            help="Name of the File System resource",
            required=True,
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.admin_password = AAZStrArg(
            options=["--admin-password"],
            arg_group="Properties",
            help="Initial administrator password of the resource",
            required=True,
        )
        _args_schema.availability_zone = AAZStrArg(
            options=["--availability-zone"],
            arg_group="Properties",
            help="Availability zone",
        )
        _args_schema.cluster_login_url = AAZStrArg(
            options=["--cluster-login-url"],
            arg_group="Properties",
            help="File system Id of the resource",
        )
        _args_schema.delegated_subnet_id = AAZStrArg(
            options=["--delegated-subnet-id"],
            arg_group="Properties",
            help="Delegated subnet id for Vnet injection",
            required=True,
        )
        _args_schema.initial_capacity = AAZIntArg(
            options=["--initial-capacity"],
            arg_group="Properties",
            help="Storage capacity in TB",
            required=True,
        )
        _args_schema.marketplace_details = AAZObjectArg(
            options=["--marketplace-details"],
            arg_group="Properties",
            help="Marketplace details",
            required=True,
        )
        _args_schema.private_ips = AAZListArg(
            options=["--private-ips"],
            arg_group="Properties",
            help="Private IPs of the resource",
        )
        _args_schema.storage_sku = AAZStrArg(
            options=["--storage-sku"],
            arg_group="Properties",
            help="Storage Sku",
            required=True,
            enum={"Performance": "Performance", "Standard": "Standard"},
        )
        _args_schema.user_details = AAZObjectArg(
            options=["--user-details"],
            arg_group="Properties",
            help="User Details",
            required=True,
        )

        marketplace_details = cls._args_schema.marketplace_details
        marketplace_details.marketplace_subscription_id = AAZStrArg(
            options=["marketplace-subscription-id"],
            help="Marketplace Subscription Id",
        )
        marketplace_details.offer_id = AAZStrArg(
            options=["offer-id"],
            help="Offer Id",
            required=True,
        )
        marketplace_details.plan_id = AAZStrArg(
            options=["plan-id"],
            help="Plan Id",
            required=True,
        )
        marketplace_details.publisher_id = AAZStrArg(
            options=["publisher-id"],
            help="Publisher Id",
            required=True,
        )

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

        user_details = cls._args_schema.user_details
        user_details.email = AAZStrArg(
            options=["email"],
            help="User Email",
            required=True,
        )

        # define Arg Group "Resource"

        _args_schema = cls._args_schema
        _args_schema.location = AAZResourceLocationArg(
            arg_group="Resource",
            help="The geo-location where the resource lives",
            required=True,
            fmt=AAZResourceLocationArgFormat(
                resource_group_arg="resource_group",
            ),
        )
        _args_schema.tags = AAZDictArg(
            options=["--tags"],
            arg_group="Resource",
            help="Resource tags.",
        )

        tags = cls._args_schema.tags
        tags.Element = AAZStrArg()
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        yield self.FileSystemsCreateOrUpdate(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, client_flatten=True)
        return result

    class FileSystemsCreateOrUpdate(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 [202]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200_201,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )
            if session.http_response.status_code in [200, 201]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200_201,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Qumulo.Storage/fileSystems/{fileSystemName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "fileSystemName", self.ctx.args.file_system_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", "2022-10-12",
                    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("location", AAZStrType, ".location", typ_kwargs={"flags": {"required": True}})
            _builder.set_prop("properties", AAZObjectType, ".", typ_kwargs={"flags": {"required": True, "client_flatten": True}})
            _builder.set_prop("tags", AAZDictType, ".tags")

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("adminPassword", AAZStrType, ".admin_password", typ_kwargs={"flags": {"required": True, "secret": True}})
                properties.set_prop("availabilityZone", AAZStrType, ".availability_zone")
                properties.set_prop("clusterLoginUrl", AAZStrType, ".cluster_login_url")
                properties.set_prop("delegatedSubnetId", AAZStrType, ".delegated_subnet_id", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("initialCapacity", AAZIntType, ".initial_capacity", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("marketplaceDetails", AAZObjectType, ".marketplace_details", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("privateIPs", AAZListType, ".private_ips")
                properties.set_prop("storageSku", AAZStrType, ".storage_sku", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("userDetails", AAZObjectType, ".user_details", typ_kwargs={"flags": {"required": True}})

            marketplace_details = _builder.get(".properties.marketplaceDetails")
            if marketplace_details is not None:
                marketplace_details.set_prop("marketplaceSubscriptionId", AAZStrType, ".marketplace_subscription_id")
                marketplace_details.set_prop("offerId", AAZStrType, ".offer_id", typ_kwargs={"flags": {"required": True}})
                marketplace_details.set_prop("planId", AAZStrType, ".plan_id", typ_kwargs={"flags": {"required": True}})
                marketplace_details.set_prop("publisherId", AAZStrType, ".publisher_id", typ_kwargs={"flags": {"required": True}})

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

            user_details = _builder.get(".properties.userDetails")
            if user_details is not None:
                user_details.set_prop("email", AAZStrType, ".email", typ_kwargs={"flags": {"required": True, "secret": True}})

            tags = _builder.get(".tags")
            if tags is not None:
                tags.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.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.identity = AAZObjectType()
            _schema_on_200_201.location = AAZStrType(
                flags={"required": True},
            )
            _schema_on_200_201.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.properties = AAZObjectType(
                flags={"required": True, "client_flatten": True},
            )
            _schema_on_200_201.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _schema_on_200_201.tags = AAZDictType()
            _schema_on_200_201.type = AAZStrType(
                flags={"read_only": True},
            )

            identity = cls._schema_on_200_201.identity
            identity.principal_id = AAZStrType(
                serialized_name="principalId",
                flags={"read_only": True},
            )
            identity.tenant_id = AAZStrType(
                serialized_name="tenantId",
                flags={"read_only": True},
            )
            identity.type = AAZStrType(
                flags={"required": True},
            )
            identity.user_assigned_identities = AAZDictType(
                serialized_name="userAssignedIdentities",
            )

            user_assigned_identities = cls._schema_on_200_201.identity.user_assigned_identities
            user_assigned_identities.Element = AAZObjectType()

            _element = cls._schema_on_200_201.identity.user_assigned_identities.Element
            _element.client_id = AAZStrType(
                serialized_name="clientId",
                flags={"read_only": True},
            )
            _element.principal_id = AAZStrType(
                serialized_name="principalId",
                flags={"read_only": True},
            )

            properties = cls._schema_on_200_201.properties
            properties.admin_password = AAZStrType(
                serialized_name="adminPassword",
                flags={"required": True, "secret": True},
            )
            properties.availability_zone = AAZStrType(
                serialized_name="availabilityZone",
            )
            properties.cluster_login_url = AAZStrType(
                serialized_name="clusterLoginUrl",
            )
            properties.delegated_subnet_id = AAZStrType(
                serialized_name="delegatedSubnetId",
                flags={"required": True},
            )
            properties.initial_capacity = AAZIntType(
                serialized_name="initialCapacity",
                flags={"required": True},
            )
            properties.marketplace_details = AAZObjectType(
                serialized_name="marketplaceDetails",
                flags={"required": True},
            )
            properties.private_i_ps = AAZListType(
                serialized_name="privateIPs",
            )
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
            )
            properties.storage_sku = AAZStrType(
                serialized_name="storageSku",
                flags={"required": True},
            )
            properties.user_details = AAZObjectType(
                serialized_name="userDetails",
                flags={"required": True},
            )

            marketplace_details = cls._schema_on_200_201.properties.marketplace_details
            marketplace_details.marketplace_subscription_id = AAZStrType(
                serialized_name="marketplaceSubscriptionId",
            )
            marketplace_details.marketplace_subscription_status = AAZStrType(
                serialized_name="marketplaceSubscriptionStatus",
            )
            marketplace_details.offer_id = AAZStrType(
                serialized_name="offerId",
                flags={"required": True},
            )
            marketplace_details.plan_id = AAZStrType(
                serialized_name="planId",
                flags={"required": True},
            )
            marketplace_details.publisher_id = AAZStrType(
                serialized_name="publisherId",
                flags={"required": True},
            )

            private_i_ps = cls._schema_on_200_201.properties.private_i_ps
            private_i_ps.Element = AAZStrType()

            user_details = cls._schema_on_200_201.properties.user_details
            user_details.email = AAZStrType(
                flags={"required": True, "secret": True},
            )

            system_data = cls._schema_on_200_201.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_201.tags
            tags.Element = AAZStrType()

            return cls._schema_on_200_201


class _CreateHelper:
    """Helper class for Create"""


__all__ = ["Create"]
