// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.recoveryservicesbackup.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.recoveryservicesbackup.fluent.ResourceGuardProxyOperationsClient;
import com.azure.resourcemanager.recoveryservicesbackup.fluent.models.ResourceGuardProxyBaseResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.fluent.models.UnlockDeleteResponseInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.ResourceGuardProxyBaseResource;
import com.azure.resourcemanager.recoveryservicesbackup.models.ResourceGuardProxyOperations;
import com.azure.resourcemanager.recoveryservicesbackup.models.UnlockDeleteRequest;
import com.azure.resourcemanager.recoveryservicesbackup.models.UnlockDeleteResponse;

public final class ResourceGuardProxyOperationsImpl implements ResourceGuardProxyOperations {
    private static final ClientLogger LOGGER = new ClientLogger(ResourceGuardProxyOperationsImpl.class);

    private final ResourceGuardProxyOperationsClient innerClient;

    private final com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager serviceManager;

    public ResourceGuardProxyOperationsImpl(
        ResourceGuardProxyOperationsClient innerClient,
        com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<ResourceGuardProxyBaseResource> getWithResponse(
        String vaultName, String resourceGroupName, String resourceGuardProxyName, Context context) {
        Response<ResourceGuardProxyBaseResourceInner> inner =
            this.serviceClient().getWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new ResourceGuardProxyBaseResourceImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public ResourceGuardProxyBaseResource get(
        String vaultName, String resourceGroupName, String resourceGuardProxyName) {
        ResourceGuardProxyBaseResourceInner inner =
            this.serviceClient().get(vaultName, resourceGroupName, resourceGuardProxyName);
        if (inner != null) {
            return new ResourceGuardProxyBaseResourceImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public Response<Void> deleteWithResponse(
        String vaultName, String resourceGroupName, String resourceGuardProxyName, Context context) {
        return this.serviceClient().deleteWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, context);
    }

    public void delete(String vaultName, String resourceGroupName, String resourceGuardProxyName) {
        this.serviceClient().delete(vaultName, resourceGroupName, resourceGuardProxyName);
    }

    public Response<UnlockDeleteResponse> unlockDeleteWithResponse(
        String vaultName,
        String resourceGroupName,
        String resourceGuardProxyName,
        UnlockDeleteRequest parameters,
        Context context) {
        Response<UnlockDeleteResponseInner> inner =
            this
                .serviceClient()
                .unlockDeleteWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, parameters, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new UnlockDeleteResponseImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public UnlockDeleteResponse unlockDelete(
        String vaultName, String resourceGroupName, String resourceGuardProxyName, UnlockDeleteRequest parameters) {
        UnlockDeleteResponseInner inner =
            this.serviceClient().unlockDelete(vaultName, resourceGroupName, resourceGuardProxyName, parameters);
        if (inner != null) {
            return new UnlockDeleteResponseImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public ResourceGuardProxyBaseResource getById(String id) {
        String vaultName = Utils.getValueFromIdByName(id, "vaults");
        if (vaultName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String resourceGuardProxyName = Utils.getValueFromIdByName(id, "backupResourceGuardProxies");
        if (resourceGuardProxyName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'backupResourceGuardProxies'.",
                                id)));
        }
        return this.getWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, Context.NONE).getValue();
    }

    public Response<ResourceGuardProxyBaseResource> getByIdWithResponse(String id, Context context) {
        String vaultName = Utils.getValueFromIdByName(id, "vaults");
        if (vaultName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String resourceGuardProxyName = Utils.getValueFromIdByName(id, "backupResourceGuardProxies");
        if (resourceGuardProxyName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'backupResourceGuardProxies'.",
                                id)));
        }
        return this.getWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, context);
    }

    public void deleteById(String id) {
        String vaultName = Utils.getValueFromIdByName(id, "vaults");
        if (vaultName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String resourceGuardProxyName = Utils.getValueFromIdByName(id, "backupResourceGuardProxies");
        if (resourceGuardProxyName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'backupResourceGuardProxies'.",
                                id)));
        }
        this.deleteWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, Context.NONE);
    }

    public Response<Void> deleteByIdWithResponse(String id, Context context) {
        String vaultName = Utils.getValueFromIdByName(id, "vaults");
        if (vaultName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vaults'.", id)));
        }
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String resourceGuardProxyName = Utils.getValueFromIdByName(id, "backupResourceGuardProxies");
        if (resourceGuardProxyName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'backupResourceGuardProxies'.",
                                id)));
        }
        return this.deleteWithResponse(vaultName, resourceGroupName, resourceGuardProxyName, context);
    }

    private ResourceGuardProxyOperationsClient serviceClient() {
        return this.innerClient;
    }

    private com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager() {
        return this.serviceManager;
    }

    public ResourceGuardProxyBaseResourceImpl define(String name) {
        return new ResourceGuardProxyBaseResourceImpl(name, this.manager());
    }
}
