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

package com.azure.resourcemanager.dataprotection.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.dataprotection.fluent.models.ResourceGuardProxyBaseResourceInner;
import com.azure.resourcemanager.dataprotection.models.ResourceGuardProxyBase;
import com.azure.resourcemanager.dataprotection.models.ResourceGuardProxyBaseResource;
import com.azure.resourcemanager.dataprotection.models.UnlockDeleteRequest;
import com.azure.resourcemanager.dataprotection.models.UnlockDeleteResponse;

public final class ResourceGuardProxyBaseResourceImpl
    implements ResourceGuardProxyBaseResource,
        ResourceGuardProxyBaseResource.Definition,
        ResourceGuardProxyBaseResource.Update {
    private ResourceGuardProxyBaseResourceInner innerObject;

    private final com.azure.resourcemanager.dataprotection.DataProtectionManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

    public ResourceGuardProxyBase properties() {
        return this.innerModel().properties();
    }

    public String resourceGroupName() {
        return resourceGroupName;
    }

    public ResourceGuardProxyBaseResourceInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.dataprotection.DataProtectionManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String vaultName;

    private String resourceGuardProxyName;

    public ResourceGuardProxyBaseResourceImpl withExistingBackupVault(String resourceGroupName, String vaultName) {
        this.resourceGroupName = resourceGroupName;
        this.vaultName = vaultName;
        return this;
    }

    public ResourceGuardProxyBaseResource create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .createOrUpdateWithResponse(
                    resourceGroupName, vaultName, resourceGuardProxyName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ResourceGuardProxyBaseResource create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .createOrUpdateWithResponse(
                    resourceGroupName, vaultName, resourceGuardProxyName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ResourceGuardProxyBaseResourceImpl(
        String name, com.azure.resourcemanager.dataprotection.DataProtectionManager serviceManager) {
        this.innerObject = new ResourceGuardProxyBaseResourceInner();
        this.serviceManager = serviceManager;
        this.resourceGuardProxyName = name;
    }

    public ResourceGuardProxyBaseResourceImpl update() {
        return this;
    }

    public ResourceGuardProxyBaseResource apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .createOrUpdateWithResponse(
                    resourceGroupName, vaultName, resourceGuardProxyName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public ResourceGuardProxyBaseResource apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .createOrUpdateWithResponse(
                    resourceGroupName, vaultName, resourceGuardProxyName, this.innerModel(), context)
                .getValue();
        return this;
    }

    ResourceGuardProxyBaseResourceImpl(
        ResourceGuardProxyBaseResourceInner innerObject,
        com.azure.resourcemanager.dataprotection.DataProtectionManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.vaultName = Utils.getValueFromIdByName(innerObject.id(), "backupVaults");
        this.resourceGuardProxyName = Utils.getValueFromIdByName(innerObject.id(), "backupResourceGuardProxies");
    }

    public ResourceGuardProxyBaseResource refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .getWithResponse(resourceGroupName, vaultName, resourceGuardProxyName, Context.NONE)
                .getValue();
        return this;
    }

    public ResourceGuardProxyBaseResource refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getDppResourceGuardProxies()
                .getWithResponse(resourceGroupName, vaultName, resourceGuardProxyName, context)
                .getValue();
        return this;
    }

    public Response<UnlockDeleteResponse> unlockDeleteWithResponse(UnlockDeleteRequest parameters, Context context) {
        return serviceManager
            .dppResourceGuardProxies()
            .unlockDeleteWithResponse(resourceGroupName, vaultName, resourceGuardProxyName, parameters, context);
    }

    public UnlockDeleteResponse unlockDelete(UnlockDeleteRequest parameters) {
        return serviceManager
            .dppResourceGuardProxies()
            .unlockDelete(resourceGroupName, vaultName, resourceGuardProxyName, parameters);
    }

    public ResourceGuardProxyBaseResourceImpl withProperties(ResourceGuardProxyBase properties) {
        this.innerModel().withProperties(properties);
        return this;
    }
}
