# --------------------------------------------------------------------------------------------
# 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(
    "dataprotection backup-vault wait",
)
class Wait(AAZWaitCommand):
    """Place the CLI in a waiting state until a condition is met.
    """

    _aaz_info = {
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dataprotection/backupvaults/{}", "2023-05-01"],
        ]
    }

    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.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.vault_name = AAZStrArg(
            options=["--vault-name"],
            help="The name of the backup vault.",
            required=True,
            id_part="name",
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.BackupVaultsGet(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=False)
        return result

    class BackupVaultsGet(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.DataProtection/backupVaults/{vaultName}",
                **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(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "subscriptionId", self.ctx.subscription_id,
                    required=True,
                ),
                **self.serialize_url_param(
                    "vaultName", self.ctx.args.vault_name,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "api-version", "2023-05-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.e_tag = AAZStrType(
                serialized_name="eTag",
            )
            _schema_on_200.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.identity = AAZObjectType()
            _schema_on_200.location = AAZStrType(
                flags={"required": True},
            )
            _schema_on_200.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.properties = AAZObjectType(
                flags={"required": True},
            )
            _schema_on_200.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _schema_on_200.tags = AAZDictType()
            _schema_on_200.type = AAZStrType(
                flags={"read_only": True},
            )

            identity = cls._schema_on_200.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()
            identity.user_assigned_identities = AAZDictType(
                serialized_name="userAssignedIdentities",
            )

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

            _element = cls._schema_on_200.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.properties
            properties.feature_settings = AAZObjectType(
                serialized_name="featureSettings",
            )
            properties.is_vault_protected_by_resource_guard = AAZBoolType(
                serialized_name="isVaultProtectedByResourceGuard",
                flags={"read_only": True},
            )
            properties.monitoring_settings = AAZObjectType(
                serialized_name="monitoringSettings",
            )
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
                flags={"read_only": True},
            )
            properties.resource_move_details = AAZObjectType(
                serialized_name="resourceMoveDetails",
            )
            properties.resource_move_state = AAZStrType(
                serialized_name="resourceMoveState",
                flags={"read_only": True},
            )
            properties.secure_score = AAZStrType(
                serialized_name="secureScore",
                flags={"read_only": True},
            )
            properties.security_settings = AAZObjectType(
                serialized_name="securitySettings",
            )
            properties.storage_settings = AAZListType(
                serialized_name="storageSettings",
                flags={"required": True},
            )

            feature_settings = cls._schema_on_200.properties.feature_settings
            feature_settings.cross_region_restore_settings = AAZObjectType(
                serialized_name="crossRegionRestoreSettings",
            )
            feature_settings.cross_subscription_restore_settings = AAZObjectType(
                serialized_name="crossSubscriptionRestoreSettings",
            )

            cross_region_restore_settings = cls._schema_on_200.properties.feature_settings.cross_region_restore_settings
            cross_region_restore_settings.state = AAZStrType()

            cross_subscription_restore_settings = cls._schema_on_200.properties.feature_settings.cross_subscription_restore_settings
            cross_subscription_restore_settings.state = AAZStrType()

            monitoring_settings = cls._schema_on_200.properties.monitoring_settings
            monitoring_settings.azure_monitor_alert_settings = AAZObjectType(
                serialized_name="azureMonitorAlertSettings",
            )

            azure_monitor_alert_settings = cls._schema_on_200.properties.monitoring_settings.azure_monitor_alert_settings
            azure_monitor_alert_settings.alerts_for_all_job_failures = AAZStrType(
                serialized_name="alertsForAllJobFailures",
            )

            resource_move_details = cls._schema_on_200.properties.resource_move_details
            resource_move_details.completion_time_utc = AAZStrType(
                serialized_name="completionTimeUtc",
            )
            resource_move_details.operation_id = AAZStrType(
                serialized_name="operationId",
            )
            resource_move_details.source_resource_path = AAZStrType(
                serialized_name="sourceResourcePath",
            )
            resource_move_details.start_time_utc = AAZStrType(
                serialized_name="startTimeUtc",
            )
            resource_move_details.target_resource_path = AAZStrType(
                serialized_name="targetResourcePath",
            )

            security_settings = cls._schema_on_200.properties.security_settings
            security_settings.immutability_settings = AAZObjectType(
                serialized_name="immutabilitySettings",
            )
            security_settings.soft_delete_settings = AAZObjectType(
                serialized_name="softDeleteSettings",
            )

            immutability_settings = cls._schema_on_200.properties.security_settings.immutability_settings
            immutability_settings.state = AAZStrType()

            soft_delete_settings = cls._schema_on_200.properties.security_settings.soft_delete_settings
            soft_delete_settings.retention_duration_in_days = AAZFloatType(
                serialized_name="retentionDurationInDays",
            )
            soft_delete_settings.state = AAZStrType()

            storage_settings = cls._schema_on_200.properties.storage_settings
            storage_settings.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.storage_settings.Element
            _element.datastore_type = AAZStrType(
                serialized_name="datastoreType",
            )
            _element.type = AAZStrType()

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

            return cls._schema_on_200


class _WaitHelper:
    """Helper class for Wait"""


__all__ = ["Wait"]
