// 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.VCenterInner;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.AddVCenterRequest;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.AddVCenterRequestProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.UpdateVCenterRequest;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.UpdateVCenterRequestProperties;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VCenter;
import com.azure.resourcemanager.recoveryservicessiterecovery.models.VCenterProperties;

public final class VCenterImpl implements VCenter, VCenter.Definition, VCenter.Update {
    private VCenterInner innerObject;

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

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

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

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

    public VCenterProperties 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 String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceName;

    private String resourceGroupName;

    private String fabricName;

    private String vcenterName;

    private AddVCenterRequest createAddVCenterRequest;

    private UpdateVCenterRequest updateUpdateVCenterRequest;

    public VCenterImpl withExistingReplicationFabric(String resourceName, String resourceGroupName, String fabricName) {
        this.resourceName = resourceName;
        this.resourceGroupName = resourceGroupName;
        this.fabricName = fabricName;
        return this;
    }

    public VCenter create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .create(
                    resourceName, resourceGroupName, fabricName, vcenterName, createAddVCenterRequest, Context.NONE);
        return this;
    }

    public VCenter create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .create(resourceName, resourceGroupName, fabricName, vcenterName, createAddVCenterRequest, context);
        return this;
    }

    VCenterImpl(
        String name, com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = new VCenterInner();
        this.serviceManager = serviceManager;
        this.vcenterName = name;
        this.createAddVCenterRequest = new AddVCenterRequest();
    }

    public VCenterImpl update() {
        this.updateUpdateVCenterRequest = new UpdateVCenterRequest();
        return this;
    }

    public VCenter apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .update(
                    resourceName, resourceGroupName, fabricName, vcenterName, updateUpdateVCenterRequest, Context.NONE);
        return this;
    }

    public VCenter apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .update(resourceName, resourceGroupName, fabricName, vcenterName, updateUpdateVCenterRequest, context);
        return this;
    }

    VCenterImpl(
        VCenterInner innerObject,
        com.azure.resourcemanager.recoveryservicessiterecovery.SiteRecoveryManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceName = Utils.getValueFromIdByName(innerObject.id(), "vaults");
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.fabricName = Utils.getValueFromIdByName(innerObject.id(), "replicationFabrics");
        this.vcenterName = Utils.getValueFromIdByName(innerObject.id(), "replicationvCenters");
    }

    public VCenter refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .getWithResponse(resourceName, resourceGroupName, fabricName, vcenterName, Context.NONE)
                .getValue();
        return this;
    }

    public VCenter refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getReplicationvCenters()
                .getWithResponse(resourceName, resourceGroupName, fabricName, vcenterName, context)
                .getValue();
        return this;
    }

    public VCenterImpl withProperties(AddVCenterRequestProperties properties) {
        this.createAddVCenterRequest.withProperties(properties);
        return this;
    }

    public VCenterImpl withProperties(UpdateVCenterRequestProperties properties) {
        this.updateUpdateVCenterRequest.withProperties(properties);
        return this;
    }
}
