# --------------------------------------------------------------------------------------------
# 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 protection-container mapping list",
)
class List(AAZCommand):
    """List the protection container mappings for a protection container.

    :example: protection-container mapping list
        az site-recovery protection-container mapping list -g rg --fabric-name fabric_source_name --protection-container container_source_name --vault-name vault_name
    """

    _aaz_info = {
        "version": "2022-08-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.recoveryservices/vaults/{}/replicationfabrics/{}/replicationprotectioncontainers/{}/replicationprotectioncontainermappings", "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.fabric_name = AAZStrArg(
            options=["--fabric-name"],
            help="Fabric name.",
            required=True,
        )
        _args_schema.protection_container_name = AAZStrArg(
            options=["--protection-container", "--protection-container-name"],
            help="Protection container name.",
            required=True,
        )
        _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.ReplicationProtectionContainerMappingsListByReplicationProtectionContainers(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 ReplicationProtectionContainerMappingsListByReplicationProtectionContainers(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}/replicationFabrics/{fabricName}/replicationProtectionContainers/{protectionContainerName}/replicationProtectionContainerMappings",
                **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(
                    "fabricName", self.ctx.args.fabric_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "protectionContainerName", self.ctx.args.protection_container_name,
                    required=True,
                ),
                **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.health = AAZStrType()
            properties.health_error_details = AAZListType(
                serialized_name="healthErrorDetails",
            )
            properties.policy_friendly_name = AAZStrType(
                serialized_name="policyFriendlyName",
            )
            properties.policy_id = AAZStrType(
                serialized_name="policyId",
            )
            properties.provider_specific_details = AAZObjectType(
                serialized_name="providerSpecificDetails",
            )
            properties.source_fabric_friendly_name = AAZStrType(
                serialized_name="sourceFabricFriendlyName",
            )
            properties.source_protection_container_friendly_name = AAZStrType(
                serialized_name="sourceProtectionContainerFriendlyName",
            )
            properties.state = AAZStrType()
            properties.target_fabric_friendly_name = AAZStrType(
                serialized_name="targetFabricFriendlyName",
            )
            properties.target_protection_container_friendly_name = AAZStrType(
                serialized_name="targetProtectionContainerFriendlyName",
            )
            properties.target_protection_container_id = AAZStrType(
                serialized_name="targetProtectionContainerId",
            )

            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_specific_details = cls._schema_on_200.value.Element.properties.provider_specific_details
            provider_specific_details.instance_type = AAZStrType(
                serialized_name="instanceType",
                flags={"required": True},
            )

            disc_a2_a = cls._schema_on_200.value.Element.properties.provider_specific_details.discriminate_by("instance_type", "A2A")
            disc_a2_a.agent_auto_update_status = AAZStrType(
                serialized_name="agentAutoUpdateStatus",
            )
            disc_a2_a.automation_account_arm_id = AAZStrType(
                serialized_name="automationAccountArmId",
            )
            disc_a2_a.automation_account_authentication_type = AAZStrType(
                serialized_name="automationAccountAuthenticationType",
            )
            disc_a2_a.job_schedule_name = AAZStrType(
                serialized_name="jobScheduleName",
            )
            disc_a2_a.schedule_name = AAZStrType(
                serialized_name="scheduleName",
            )

            disc_in_mage_rcm = cls._schema_on_200.value.Element.properties.provider_specific_details.discriminate_by("instance_type", "InMageRcm")
            disc_in_mage_rcm.enable_agent_auto_upgrade = AAZStrType(
                serialized_name="enableAgentAutoUpgrade",
                flags={"read_only": True},
            )

            disc_v_mware_cbt = cls._schema_on_200.value.Element.properties.provider_specific_details.discriminate_by("instance_type", "VMwareCbt")
            disc_v_mware_cbt.key_vault_id = AAZStrType(
                serialized_name="keyVaultId",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.key_vault_uri = AAZStrType(
                serialized_name="keyVaultUri",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.role_size_to_nic_count_map = AAZDictType(
                serialized_name="roleSizeToNicCountMap",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.service_bus_connection_string_secret_name = AAZStrType(
                serialized_name="serviceBusConnectionStringSecretName",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.storage_account_id = AAZStrType(
                serialized_name="storageAccountId",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.storage_account_sas_secret_name = AAZStrType(
                serialized_name="storageAccountSasSecretName",
                flags={"read_only": True},
            )
            disc_v_mware_cbt.target_location = AAZStrType(
                serialized_name="targetLocation",
                flags={"read_only": True},
            )

            role_size_to_nic_count_map = cls._schema_on_200.value.Element.properties.provider_specific_details.discriminate_by("instance_type", "VMwareCbt").role_size_to_nic_count_map
            role_size_to_nic_count_map.Element = AAZIntType()

            return cls._schema_on_200


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


__all__ = ["List"]
