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

package com.azure.resourcemanager.recoveryservicessiterecovery.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.recoveryservicessiterecovery.fluent.models.VaultSettingInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VaultSetting;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VaultSettingCreationInput;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VaultSettingCreationInputProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VaultSettingProperties;

public final class VaultSettingImpl implements VaultSetting, VaultSetting.Definition {
    private VaultSettingInner innerObject;

    private final com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager;

    VaultSettingImpl(
        VaultSettingInner innerObject,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
    }

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

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

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

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

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

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

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

    private com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager manager() {
        return this.serviceManager;
    }

    private String resourceName;

    private String resourceGroupName;

    private String vaultSettingName;

    private VaultSettingCreationInput createInput;

    public VaultSettingImpl withExistingVault(String resourceName, String resourceGroupName) {
        this.resourceName = resourceName;
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public VaultSetting create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationVaultSettings()
                .create(resourceName, resourceGroupName, vaultSettingName, createInput, Context.NONE);
        return this;
    }

    public VaultSetting create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationVaultSettings()
                .create(resourceName, resourceGroupName, vaultSettingName, createInput, context);
        return this;
    }

    VaultSettingImpl(
        String name, com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = new VaultSettingInner();
        this.serviceManager = serviceManager;
        this.vaultSettingName = name;
        this.createInput = new VaultSettingCreationInput();
    }

    public VaultSetting refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationVaultSettings()
                .getWithResponse(resourceName, resourceGroupName, vaultSettingName, Context.NONE)
                .getValue();
        return this;
    }

    public VaultSetting refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationVaultSettings()
                .getWithResponse(resourceName, resourceGroupName, vaultSettingName, context)
                .getValue();
        return this;
    }

    public VaultSettingImpl withProperties(VaultSettingCreationInputProperties properties) {
        this.createInput.withProperties(properties);
        return this;
    }
}
