# --------------------------------------------------------------------------------------------
# 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(
    "site-recovery vault list-recovery-services-provider",
)
class ListRecoveryServicesProvider(AAZCommand):
    """List the registered recovery services providers in the vault.

    :example: list-recovery-services-provider
        az site-recovery vault list-recovery-services-provider -g rg --vault-name vault_name
    """

    _aaz_info = {
        "version": "2022-08-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.recoveryservices/vaults/{}/replicationrecoveryservicesproviders", "2022-08-01"],
        ]
    }

    AZ_SUPPORT_PAGINATION = True

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

    def _execute_operations(self):
        self.pre_operations()
        self.ReplicationRecoveryServicesProvidersList(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 ReplicationRecoveryServicesProvidersList(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.RecoveryServices/vaults/{resourceName}/replicationRecoveryServicesProviders",
                **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(
                    "resourceName", self.ctx.args.vault_name,
                    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-08-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.id = AAZStrType(
                flags={"read_only": True},
            )
            _element.location = AAZStrType()
            _element.name = AAZStrType(
                flags={"read_only": True},
            )
            _element.properties = AAZObjectType()
            _element.type = AAZStrType(
                flags={"read_only": True},
            )

            properties = cls._schema_on_200.value.Element.properties
            properties.allowed_scenarios = AAZListType(
                serialized_name="allowedScenarios",
            )
            properties.authentication_identity_details = AAZObjectType(
                serialized_name="authenticationIdentityDetails",
            )
            _ListRecoveryServicesProviderHelper._build_schema_identity_provider_details_read(properties.authentication_identity_details)
            properties.bios_id = AAZStrType(
                serialized_name="biosId",
            )
            properties.connection_status = AAZStrType(
                serialized_name="connectionStatus",
            )
            properties.data_plane_authentication_identity_details = AAZObjectType(
                serialized_name="dataPlaneAuthenticationIdentityDetails",
            )
            _ListRecoveryServicesProviderHelper._build_schema_identity_provider_details_read(properties.data_plane_authentication_identity_details)
            properties.dra_identifier = AAZStrType(
                serialized_name="draIdentifier",
            )
            properties.fabric_friendly_name = AAZStrType(
                serialized_name="fabricFriendlyName",
            )
            properties.fabric_type = AAZStrType(
                serialized_name="fabricType",
            )
            properties.friendly_name = AAZStrType(
                serialized_name="friendlyName",
            )
            properties.health_error_details = AAZListType(
                serialized_name="healthErrorDetails",
            )
            properties.last_heart_beat = AAZStrType(
                serialized_name="lastHeartBeat",
            )
            properties.machine_id = AAZStrType(
                serialized_name="machineId",
            )
            properties.machine_name = AAZStrType(
                serialized_name="machineName",
            )
            properties.protected_item_count = AAZIntType(
                serialized_name="protectedItemCount",
            )
            properties.provider_version = AAZStrType(
                serialized_name="providerVersion",
            )
            properties.provider_version_details = AAZObjectType(
                serialized_name="providerVersionDetails",
            )
            properties.provider_version_expiry_date = AAZStrType(
                serialized_name="providerVersionExpiryDate",
            )
            properties.provider_version_state = AAZStrType(
                serialized_name="providerVersionState",
            )
            properties.resource_access_identity_details = AAZObjectType(
                serialized_name="resourceAccessIdentityDetails",
            )
            _ListRecoveryServicesProviderHelper._build_schema_identity_provider_details_read(properties.resource_access_identity_details)
            properties.server_version = AAZStrType(
                serialized_name="serverVersion",
            )

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

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

            _element = cls._schema_on_200.value.Element.properties.health_error_details.Element
            _element.creation_time_utc = AAZStrType(
                serialized_name="creationTimeUtc",
            )
            _element.customer_resolvability = AAZStrType(
                serialized_name="customerResolvability",
            )
            _element.entity_id = AAZStrType(
                serialized_name="entityId",
            )
            _element.error_category = AAZStrType(
                serialized_name="errorCategory",
            )
            _element.error_code = AAZStrType(
                serialized_name="errorCode",
            )
            _element.error_id = AAZStrType(
                serialized_name="errorId",
            )
            _element.error_level = AAZStrType(
                serialized_name="errorLevel",
            )
            _element.error_message = AAZStrType(
                serialized_name="errorMessage",
            )
            _element.error_source = AAZStrType(
                serialized_name="errorSource",
            )
            _element.error_type = AAZStrType(
                serialized_name="errorType",
            )
            _element.inner_health_errors = AAZListType(
                serialized_name="innerHealthErrors",
            )
            _element.possible_causes = AAZStrType(
                serialized_name="possibleCauses",
            )
            _element.recommended_action = AAZStrType(
                serialized_name="recommendedAction",
            )
            _element.recovery_provider_error_message = AAZStrType(
                serialized_name="recoveryProviderErrorMessage",
            )
            _element.summary_message = AAZStrType(
                serialized_name="summaryMessage",
            )

            inner_health_errors = cls._schema_on_200.value.Element.properties.health_error_details.Element.inner_health_errors
            inner_health_errors.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.properties.health_error_details.Element.inner_health_errors.Element
            _element.creation_time_utc = AAZStrType(
                serialized_name="creationTimeUtc",
            )
            _element.customer_resolvability = AAZStrType(
                serialized_name="customerResolvability",
            )
            _element.entity_id = AAZStrType(
                serialized_name="entityId",
            )
            _element.error_category = AAZStrType(
                serialized_name="errorCategory",
            )
            _element.error_code = AAZStrType(
                serialized_name="errorCode",
            )
            _element.error_id = AAZStrType(
                serialized_name="errorId",
            )
            _element.error_level = AAZStrType(
                serialized_name="errorLevel",
            )
            _element.error_message = AAZStrType(
                serialized_name="errorMessage",
            )
            _element.error_source = AAZStrType(
                serialized_name="errorSource",
            )
            _element.error_type = AAZStrType(
                serialized_name="errorType",
            )
            _element.possible_causes = AAZStrType(
                serialized_name="possibleCauses",
            )
            _element.recommended_action = AAZStrType(
                serialized_name="recommendedAction",
            )
            _element.recovery_provider_error_message = AAZStrType(
                serialized_name="recoveryProviderErrorMessage",
            )
            _element.summary_message = AAZStrType(
                serialized_name="summaryMessage",
            )

            provider_version_details = cls._schema_on_200.value.Element.properties.provider_version_details
            provider_version_details.expiry_date = AAZStrType(
                serialized_name="expiryDate",
            )
            provider_version_details.status = AAZStrType()
            provider_version_details.version = AAZStrType()

            return cls._schema_on_200


class _ListRecoveryServicesProviderHelper:
    """Helper class for ListRecoveryServicesProvider"""

    _schema_identity_provider_details_read = None

    @classmethod
    def _build_schema_identity_provider_details_read(cls, _schema):
        if cls._schema_identity_provider_details_read is not None:
            _schema.aad_authority = cls._schema_identity_provider_details_read.aad_authority
            _schema.application_id = cls._schema_identity_provider_details_read.application_id
            _schema.audience = cls._schema_identity_provider_details_read.audience
            _schema.object_id = cls._schema_identity_provider_details_read.object_id
            _schema.tenant_id = cls._schema_identity_provider_details_read.tenant_id
            return

        cls._schema_identity_provider_details_read = _schema_identity_provider_details_read = AAZObjectType()

        identity_provider_details_read = _schema_identity_provider_details_read
        identity_provider_details_read.aad_authority = AAZStrType(
            serialized_name="aadAuthority",
        )
        identity_provider_details_read.application_id = AAZStrType(
            serialized_name="applicationId",
        )
        identity_provider_details_read.audience = AAZStrType()
        identity_provider_details_read.object_id = AAZStrType(
            serialized_name="objectId",
        )
        identity_provider_details_read.tenant_id = AAZStrType(
            serialized_name="tenantId",
        )

        _schema.aad_authority = cls._schema_identity_provider_details_read.aad_authority
        _schema.application_id = cls._schema_identity_provider_details_read.application_id
        _schema.audience = cls._schema_identity_provider_details_read.audience
        _schema.object_id = cls._schema_identity_provider_details_read.object_id
        _schema.tenant_id = cls._schema_identity_provider_details_read.tenant_id


__all__ = ["ListRecoveryServicesProvider"]
