# coding=utf-8
# --------------------------------------------------------------------------
# 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 Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from copy import deepcopy
from typing import Any, Awaitable, Optional, TYPE_CHECKING, cast
from typing_extensions import Self

from azure.core.pipeline import policies
from azure.core.rest import AsyncHttpResponse, HttpRequest
from azure.core.settings import settings
from azure.mgmt.core import AsyncARMPipelineClient
from azure.mgmt.core.policies import AsyncARMAutoResourceProviderRegistrationPolicy
from azure.mgmt.core.tools import get_arm_endpoints

from .._utils.serialization import Deserializer, Serializer
from ._configuration import RecoveryServicesBackupClientConfiguration
from .operations import (
    BMSPrepareDataMoveOperationResultOperations,
    BackupEnginesOperations,
    BackupJobsOperations,
    BackupOperationResultsOperations,
    BackupOperationStatusesOperations,
    BackupPoliciesOperations,
    BackupProtectableItemsOperations,
    BackupProtectedItemsOperations,
    BackupProtectionContainersOperations,
    BackupProtectionIntentOperations,
    BackupResourceEncryptionConfigsOperations,
    BackupResourceStorageConfigsNonCRROperations,
    BackupResourceVaultConfigsOperations,
    BackupStatusOperations,
    BackupUsageSummariesOperations,
    BackupWorkloadItemsOperations,
    BackupsOperations,
    DeletedProtectionContainersOperations,
    ExportJobsOperationResultsOperations,
    FeatureSupportOperations,
    FetchTieringCostOperations,
    GetTieringCostOperationResultOperations,
    ItemLevelRecoveryConnectionsOperations,
    JobCancellationsOperations,
    JobDetailsOperations,
    JobOperationResultsOperations,
    JobsOperations,
    OperationOperations,
    Operations,
    PrivateEndpointConnectionOperations,
    PrivateEndpointOperations,
    ProtectableContainersOperations,
    ProtectedItemOperationResultsOperations,
    ProtectedItemOperationStatusesOperations,
    ProtectedItemsOperations,
    ProtectionContainerOperationResultsOperations,
    ProtectionContainerRefreshOperationResultsOperations,
    ProtectionContainersOperations,
    ProtectionIntentOperations,
    ProtectionPoliciesOperations,
    ProtectionPolicyOperationResultsOperations,
    ProtectionPolicyOperationStatusesOperations,
    RecoveryPointsOperations,
    RecoveryPointsRecommendedForMoveOperations,
    ResourceGuardProxiesOperations,
    ResourceGuardProxyOperations,
    RestoresOperations,
    SecurityPINsOperations,
    TieringCostOperationStatusOperations,
    ValidateOperationOperations,
    ValidateOperationResultsOperations,
    ValidateOperationStatusesOperations,
    _RecoveryServicesBackupClientOperationsMixin,
)

if TYPE_CHECKING:
    from azure.core import AzureClouds
    from azure.core.credentials_async import AsyncTokenCredential


class RecoveryServicesBackupClient(
    _RecoveryServicesBackupClientOperationsMixin
):  # pylint: disable=too-many-instance-attributes
    """Open API 2.0 Specs for Azure RecoveryServices Backup service.

    :ivar operations: Operations operations
    :vartype operations: azure.mgmt.recoveryservicesbackup.aio.operations.Operations
    :ivar backup_resource_storage_configs_non_crr: BackupResourceStorageConfigsNonCRROperations
     operations
    :vartype backup_resource_storage_configs_non_crr:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupResourceStorageConfigsNonCRROperations
    :ivar bms_prepare_data_move_operation_result: BMSPrepareDataMoveOperationResultOperations
     operations
    :vartype bms_prepare_data_move_operation_result:
     azure.mgmt.recoveryservicesbackup.aio.operations.BMSPrepareDataMoveOperationResultOperations
    :ivar backup_resource_vault_configs: BackupResourceVaultConfigsOperations operations
    :vartype backup_resource_vault_configs:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupResourceVaultConfigsOperations
    :ivar backup_resource_encryption_configs: BackupResourceEncryptionConfigsOperations operations
    :vartype backup_resource_encryption_configs:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupResourceEncryptionConfigsOperations
    :ivar protected_items: ProtectedItemsOperations operations
    :vartype protected_items:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectedItemsOperations
    :ivar backups: BackupsOperations operations
    :vartype backups: azure.mgmt.recoveryservicesbackup.aio.operations.BackupsOperations
    :ivar recovery_points_recommended_for_move: RecoveryPointsRecommendedForMoveOperations
     operations
    :vartype recovery_points_recommended_for_move:
     azure.mgmt.recoveryservicesbackup.aio.operations.RecoveryPointsRecommendedForMoveOperations
    :ivar protected_item_operation_statuses: ProtectedItemOperationStatusesOperations operations
    :vartype protected_item_operation_statuses:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectedItemOperationStatusesOperations
    :ivar protected_item_operation_results: ProtectedItemOperationResultsOperations operations
    :vartype protected_item_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectedItemOperationResultsOperations
    :ivar protection_containers: ProtectionContainersOperations operations
    :vartype protection_containers:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionContainersOperations
    :ivar backup_workload_items: BackupWorkloadItemsOperations operations
    :vartype backup_workload_items:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupWorkloadItemsOperations
    :ivar protection_container_operation_results: ProtectionContainerOperationResultsOperations
     operations
    :vartype protection_container_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionContainerOperationResultsOperations
    :ivar recovery_points: RecoveryPointsOperations operations
    :vartype recovery_points:
     azure.mgmt.recoveryservicesbackup.aio.operations.RecoveryPointsOperations
    :ivar restores: RestoresOperations operations
    :vartype restores: azure.mgmt.recoveryservicesbackup.aio.operations.RestoresOperations
    :ivar item_level_recovery_connections: ItemLevelRecoveryConnectionsOperations operations
    :vartype item_level_recovery_connections:
     azure.mgmt.recoveryservicesbackup.aio.operations.ItemLevelRecoveryConnectionsOperations
    :ivar protection_policies: ProtectionPoliciesOperations operations
    :vartype protection_policies:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionPoliciesOperations
    :ivar backup_policies: BackupPoliciesOperations operations
    :vartype backup_policies:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupPoliciesOperations
    :ivar protection_policy_operation_results: ProtectionPolicyOperationResultsOperations
     operations
    :vartype protection_policy_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionPolicyOperationResultsOperations
    :ivar protection_policy_operation_statuses: ProtectionPolicyOperationStatusesOperations
     operations
    :vartype protection_policy_operation_statuses:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionPolicyOperationStatusesOperations
    :ivar job_details: JobDetailsOperations operations
    :vartype job_details: azure.mgmt.recoveryservicesbackup.aio.operations.JobDetailsOperations
    :ivar backup_jobs: BackupJobsOperations operations
    :vartype backup_jobs: azure.mgmt.recoveryservicesbackup.aio.operations.BackupJobsOperations
    :ivar job_cancellations: JobCancellationsOperations operations
    :vartype job_cancellations:
     azure.mgmt.recoveryservicesbackup.aio.operations.JobCancellationsOperations
    :ivar job_operation_results: JobOperationResultsOperations operations
    :vartype job_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.JobOperationResultsOperations
    :ivar export_jobs_operation_results: ExportJobsOperationResultsOperations operations
    :vartype export_jobs_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ExportJobsOperationResultsOperations
    :ivar backup_engines: BackupEnginesOperations operations
    :vartype backup_engines:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupEnginesOperations
    :ivar resource_guard_proxy: ResourceGuardProxyOperations operations
    :vartype resource_guard_proxy:
     azure.mgmt.recoveryservicesbackup.aio.operations.ResourceGuardProxyOperations
    :ivar resource_guard_proxies: ResourceGuardProxiesOperations operations
    :vartype resource_guard_proxies:
     azure.mgmt.recoveryservicesbackup.aio.operations.ResourceGuardProxiesOperations
    :ivar backup_status: BackupStatusOperations operations
    :vartype backup_status: azure.mgmt.recoveryservicesbackup.aio.operations.BackupStatusOperations
    :ivar feature_support: FeatureSupportOperations operations
    :vartype feature_support:
     azure.mgmt.recoveryservicesbackup.aio.operations.FeatureSupportOperations
    :ivar backup_protection_intent: BackupProtectionIntentOperations operations
    :vartype backup_protection_intent:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupProtectionIntentOperations
    :ivar backup_usage_summaries: BackupUsageSummariesOperations operations
    :vartype backup_usage_summaries:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupUsageSummariesOperations
    :ivar jobs: JobsOperations operations
    :vartype jobs: azure.mgmt.recoveryservicesbackup.aio.operations.JobsOperations
    :ivar backup_protected_items: BackupProtectedItemsOperations operations
    :vartype backup_protected_items:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupProtectedItemsOperations
    :ivar validate_operation: ValidateOperationOperations operations
    :vartype validate_operation:
     azure.mgmt.recoveryservicesbackup.aio.operations.ValidateOperationOperations
    :ivar validate_operation_results: ValidateOperationResultsOperations operations
    :vartype validate_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ValidateOperationResultsOperations
    :ivar validate_operation_statuses: ValidateOperationStatusesOperations operations
    :vartype validate_operation_statuses:
     azure.mgmt.recoveryservicesbackup.aio.operations.ValidateOperationStatusesOperations
    :ivar protection_container_refresh_operation_results:
     ProtectionContainerRefreshOperationResultsOperations operations
    :vartype protection_container_refresh_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionContainerRefreshOperationResultsOperations
    :ivar protectable_containers: ProtectableContainersOperations operations
    :vartype protectable_containers:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectableContainersOperations
    :ivar backup_operation_results: BackupOperationResultsOperations operations
    :vartype backup_operation_results:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupOperationResultsOperations
    :ivar backup_operation_statuses: BackupOperationStatusesOperations operations
    :vartype backup_operation_statuses:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupOperationStatusesOperations
    :ivar backup_protectable_items: BackupProtectableItemsOperations operations
    :vartype backup_protectable_items:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupProtectableItemsOperations
    :ivar backup_protection_containers: BackupProtectionContainersOperations operations
    :vartype backup_protection_containers:
     azure.mgmt.recoveryservicesbackup.aio.operations.BackupProtectionContainersOperations
    :ivar deleted_protection_containers: DeletedProtectionContainersOperations operations
    :vartype deleted_protection_containers:
     azure.mgmt.recoveryservicesbackup.aio.operations.DeletedProtectionContainersOperations
    :ivar security_pins: SecurityPINsOperations operations
    :vartype security_pins: azure.mgmt.recoveryservicesbackup.aio.operations.SecurityPINsOperations
    :ivar fetch_tiering_cost: FetchTieringCostOperations operations
    :vartype fetch_tiering_cost:
     azure.mgmt.recoveryservicesbackup.aio.operations.FetchTieringCostOperations
    :ivar get_tiering_cost_operation_result: GetTieringCostOperationResultOperations operations
    :vartype get_tiering_cost_operation_result:
     azure.mgmt.recoveryservicesbackup.aio.operations.GetTieringCostOperationResultOperations
    :ivar tiering_cost_operation_status: TieringCostOperationStatusOperations operations
    :vartype tiering_cost_operation_status:
     azure.mgmt.recoveryservicesbackup.aio.operations.TieringCostOperationStatusOperations
    :ivar protection_intent: ProtectionIntentOperations operations
    :vartype protection_intent:
     azure.mgmt.recoveryservicesbackup.aio.operations.ProtectionIntentOperations
    :ivar private_endpoint_connection: PrivateEndpointConnectionOperations operations
    :vartype private_endpoint_connection:
     azure.mgmt.recoveryservicesbackup.aio.operations.PrivateEndpointConnectionOperations
    :ivar private_endpoint: PrivateEndpointOperations operations
    :vartype private_endpoint:
     azure.mgmt.recoveryservicesbackup.aio.operations.PrivateEndpointOperations
    :ivar operation: OperationOperations operations
    :vartype operation: azure.mgmt.recoveryservicesbackup.aio.operations.OperationOperations
    :param credential: Credential used to authenticate requests to the service. Required.
    :type credential: ~azure.core.credentials_async.AsyncTokenCredential
    :param subscription_id: The ID of the target subscription. The value must be an UUID. Required.
    :type subscription_id: str
    :param base_url: Service host. Default value is None.
    :type base_url: str
    :keyword cloud_setting: The cloud setting for which to get the ARM endpoint. Default value is
     None.
    :paramtype cloud_setting: ~azure.core.AzureClouds
    :keyword api_version: The API version to use for this operation. Known values are
     "2026-01-31-preview". Default value is "2026-01-31-preview". Note that overriding this default
     value may result in unsupported behavior.
    :paramtype api_version: str
    :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
     Retry-After header is present.
    """

    def __init__(
        self,
        credential: "AsyncTokenCredential",
        subscription_id: str,
        base_url: Optional[str] = None,
        *,
        cloud_setting: Optional["AzureClouds"] = None,
        **kwargs: Any
    ) -> None:
        _endpoint = "{endpoint}"
        _cloud = cloud_setting or settings.current.azure_cloud  # type: ignore
        _endpoints = get_arm_endpoints(_cloud)
        if not base_url:
            base_url = _endpoints["resource_manager"]
        credential_scopes = kwargs.pop("credential_scopes", _endpoints["credential_scopes"])
        self._config = RecoveryServicesBackupClientConfiguration(
            credential=credential,
            subscription_id=subscription_id,
            base_url=cast(str, base_url),
            cloud_setting=cloud_setting,
            credential_scopes=credential_scopes,
            **kwargs
        )

        _policies = kwargs.pop("policies", None)
        if _policies is None:
            _policies = [
                policies.RequestIdPolicy(**kwargs),
                self._config.headers_policy,
                self._config.user_agent_policy,
                self._config.proxy_policy,
                policies.ContentDecodePolicy(**kwargs),
                AsyncARMAutoResourceProviderRegistrationPolicy(),
                self._config.redirect_policy,
                self._config.retry_policy,
                self._config.authentication_policy,
                self._config.custom_hook_policy,
                self._config.logging_policy,
                policies.DistributedTracingPolicy(**kwargs),
                policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
                self._config.http_logging_policy,
            ]
        self._client: AsyncARMPipelineClient = AsyncARMPipelineClient(
            base_url=cast(str, _endpoint), policies=_policies, **kwargs
        )

        self._serialize = Serializer()
        self._deserialize = Deserializer()
        self._serialize.client_side_validation = False
        self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
        self.backup_resource_storage_configs_non_crr = BackupResourceStorageConfigsNonCRROperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.bms_prepare_data_move_operation_result = BMSPrepareDataMoveOperationResultOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_resource_vault_configs = BackupResourceVaultConfigsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_resource_encryption_configs = BackupResourceEncryptionConfigsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protected_items = ProtectedItemsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.backups = BackupsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.recovery_points_recommended_for_move = RecoveryPointsRecommendedForMoveOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protected_item_operation_statuses = ProtectedItemOperationStatusesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protected_item_operation_results = ProtectedItemOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_containers = ProtectionContainersOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_workload_items = BackupWorkloadItemsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_container_operation_results = ProtectionContainerOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.recovery_points = RecoveryPointsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.restores = RestoresOperations(self._client, self._config, self._serialize, self._deserialize)
        self.item_level_recovery_connections = ItemLevelRecoveryConnectionsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_policies = ProtectionPoliciesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_policies = BackupPoliciesOperations(self._client, self._config, self._serialize, self._deserialize)
        self.protection_policy_operation_results = ProtectionPolicyOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_policy_operation_statuses = ProtectionPolicyOperationStatusesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.job_details = JobDetailsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.backup_jobs = BackupJobsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.job_cancellations = JobCancellationsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.job_operation_results = JobOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.export_jobs_operation_results = ExportJobsOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_engines = BackupEnginesOperations(self._client, self._config, self._serialize, self._deserialize)
        self.resource_guard_proxy = ResourceGuardProxyOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.resource_guard_proxies = ResourceGuardProxiesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_status = BackupStatusOperations(self._client, self._config, self._serialize, self._deserialize)
        self.feature_support = FeatureSupportOperations(self._client, self._config, self._serialize, self._deserialize)
        self.backup_protection_intent = BackupProtectionIntentOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_usage_summaries = BackupUsageSummariesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.backup_protected_items = BackupProtectedItemsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.validate_operation = ValidateOperationOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.validate_operation_results = ValidateOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.validate_operation_statuses = ValidateOperationStatusesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_container_refresh_operation_results = ProtectionContainerRefreshOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protectable_containers = ProtectableContainersOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_operation_results = BackupOperationResultsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_operation_statuses = BackupOperationStatusesOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_protectable_items = BackupProtectableItemsOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.backup_protection_containers = BackupProtectionContainersOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.deleted_protection_containers = DeletedProtectionContainersOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.security_pins = SecurityPINsOperations(self._client, self._config, self._serialize, self._deserialize)
        self.fetch_tiering_cost = FetchTieringCostOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.get_tiering_cost_operation_result = GetTieringCostOperationResultOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.tiering_cost_operation_status = TieringCostOperationStatusOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.protection_intent = ProtectionIntentOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.private_endpoint_connection = PrivateEndpointConnectionOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.private_endpoint = PrivateEndpointOperations(
            self._client, self._config, self._serialize, self._deserialize
        )
        self.operation = OperationOperations(self._client, self._config, self._serialize, self._deserialize)

    def send_request(
        self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
    ) -> Awaitable[AsyncHttpResponse]:
        """Runs the network request through the client's chained policies.

        >>> from azure.core.rest import HttpRequest
        >>> request = HttpRequest("GET", "https://www.example.org/")
        <HttpRequest [GET], url: 'https://www.example.org/'>
        >>> response = await client.send_request(request)
        <AsyncHttpResponse: 200 OK>

        For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

        :param request: The network request you want to make. Required.
        :type request: ~azure.core.rest.HttpRequest
        :keyword bool stream: Whether the response payload will be streamed. Defaults to False.
        :return: The response of your network call. Does not do error handling on your response.
        :rtype: ~azure.core.rest.AsyncHttpResponse
        """

        request_copy = deepcopy(request)
        path_format_arguments = {
            "endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True),
        }

        request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
        return self._client.send_request(request_copy, stream=stream, **kwargs)  # type: ignore

    async def close(self) -> None:
        await self._client.close()

    async def __aenter__(self) -> Self:
        await self._client.__aenter__()
        return self

    async def __aexit__(self, *exc_details: Any) -> None:
        await self._client.__aexit__(*exc_details)
