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

package com.azure.resourcemanager.avs.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.avs.fluent.models.PrivateCloudInner;
import com.azure.resourcemanager.avs.models.AdminCredentials;
import com.azure.resourcemanager.avs.models.AvailabilityProperties;
import com.azure.resourcemanager.avs.models.Circuit;
import com.azure.resourcemanager.avs.models.Encryption;
import com.azure.resourcemanager.avs.models.Endpoints;
import com.azure.resourcemanager.avs.models.IdentitySource;
import com.azure.resourcemanager.avs.models.InternetEnum;
import com.azure.resourcemanager.avs.models.ManagementCluster;
import com.azure.resourcemanager.avs.models.NsxPublicIpQuotaRaisedEnum;
import com.azure.resourcemanager.avs.models.PrivateCloud;
import com.azure.resourcemanager.avs.models.PrivateCloudIdentity;
import com.azure.resourcemanager.avs.models.PrivateCloudProvisioningState;
import com.azure.resourcemanager.avs.models.PrivateCloudUpdate;
import com.azure.resourcemanager.avs.models.Sku;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class PrivateCloudImpl implements PrivateCloud, PrivateCloud.Definition, PrivateCloud.Update {
    private PrivateCloudInner innerObject;

    private final com.azure.resourcemanager.avs.AvsManager serviceManager;

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

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

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

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

    public Map<String, String> tags() {
        Map<String, String> inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public Sku sku() {
        return this.innerModel().sku();
    }

    public PrivateCloudIdentity identity() {
        return this.innerModel().identity();
    }

    public PrivateCloudProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public Circuit circuit() {
        return this.innerModel().circuit();
    }

    public Endpoints endpoints() {
        return this.innerModel().endpoints();
    }

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

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

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

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

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

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

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

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

    public List<String> externalCloudLinks() {
        List<String> inner = this.innerModel().externalCloudLinks();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public Circuit secondaryCircuit() {
        return this.innerModel().secondaryCircuit();
    }

    public NsxPublicIpQuotaRaisedEnum nsxPublicIpQuotaRaised() {
        return this.innerModel().nsxPublicIpQuotaRaised();
    }

    public ManagementCluster managementCluster() {
        return this.innerModel().managementCluster();
    }

    public InternetEnum internet() {
        return this.innerModel().internet();
    }

    public List<IdentitySource> identitySources() {
        List<IdentitySource> inner = this.innerModel().identitySources();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

    public AvailabilityProperties availability() {
        return this.innerModel().availability();
    }

    public Encryption encryption() {
        return this.innerModel().encryption();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.avs.AvsManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String privateCloudName;

    private PrivateCloudUpdate updatePrivateCloudUpdate;

    public PrivateCloudImpl withExistingResourceGroup(String resourceGroupName) {
        this.resourceGroupName = resourceGroupName;
        return this;
    }

    public PrivateCloud create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .createOrUpdate(resourceGroupName, privateCloudName, this.innerModel(), Context.NONE);
        return this;
    }

    public PrivateCloud create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .createOrUpdate(resourceGroupName, privateCloudName, this.innerModel(), context);
        return this;
    }

    PrivateCloudImpl(String name, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = new PrivateCloudInner();
        this.serviceManager = serviceManager;
        this.privateCloudName = name;
    }

    public PrivateCloudImpl update() {
        this.updatePrivateCloudUpdate = new PrivateCloudUpdate();
        return this;
    }

    public PrivateCloud apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .update(resourceGroupName, privateCloudName, updatePrivateCloudUpdate, Context.NONE);
        return this;
    }

    public PrivateCloud apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .update(resourceGroupName, privateCloudName, updatePrivateCloudUpdate, context);
        return this;
    }

    PrivateCloudImpl(PrivateCloudInner innerObject, com.azure.resourcemanager.avs.AvsManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.privateCloudName = Utils.getValueFromIdByName(innerObject.id(), "privateClouds");
    }

    public PrivateCloud refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .getByResourceGroupWithResponse(resourceGroupName, privateCloudName, Context.NONE)
                .getValue();
        return this;
    }

    public PrivateCloud refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getPrivateClouds()
                .getByResourceGroupWithResponse(resourceGroupName, privateCloudName, context)
                .getValue();
        return this;
    }

    public void rotateVcenterPassword() {
        serviceManager.privateClouds().rotateVcenterPassword(resourceGroupName, privateCloudName);
    }

    public void rotateVcenterPassword(Context context) {
        serviceManager.privateClouds().rotateVcenterPassword(resourceGroupName, privateCloudName, context);
    }

    public void rotateNsxtPassword() {
        serviceManager.privateClouds().rotateNsxtPassword(resourceGroupName, privateCloudName);
    }

    public void rotateNsxtPassword(Context context) {
        serviceManager.privateClouds().rotateNsxtPassword(resourceGroupName, privateCloudName, context);
    }

    public Response<AdminCredentials> listAdminCredentialsWithResponse(Context context) {
        return serviceManager
            .privateClouds()
            .listAdminCredentialsWithResponse(resourceGroupName, privateCloudName, context);
    }

    public AdminCredentials listAdminCredentials() {
        return serviceManager.privateClouds().listAdminCredentials(resourceGroupName, privateCloudName);
    }

    public PrivateCloudImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

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

    public PrivateCloudImpl withSku(Sku sku) {
        this.innerModel().withSku(sku);
        return this;
    }

    public PrivateCloudImpl withTags(Map<String, String> tags) {
        if (isInCreateMode()) {
            this.innerModel().withTags(tags);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withTags(tags);
            return this;
        }
    }

    public PrivateCloudImpl withIdentity(PrivateCloudIdentity identity) {
        if (isInCreateMode()) {
            this.innerModel().withIdentity(identity);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withIdentity(identity);
            return this;
        }
    }

    public PrivateCloudImpl withCircuit(Circuit circuit) {
        this.innerModel().withCircuit(circuit);
        return this;
    }

    public PrivateCloudImpl withNetworkBlock(String networkBlock) {
        this.innerModel().withNetworkBlock(networkBlock);
        return this;
    }

    public PrivateCloudImpl withVcenterPassword(String vcenterPassword) {
        this.innerModel().withVcenterPassword(vcenterPassword);
        return this;
    }

    public PrivateCloudImpl withNsxtPassword(String nsxtPassword) {
        this.innerModel().withNsxtPassword(nsxtPassword);
        return this;
    }

    public PrivateCloudImpl withSecondaryCircuit(Circuit secondaryCircuit) {
        this.innerModel().withSecondaryCircuit(secondaryCircuit);
        return this;
    }

    public PrivateCloudImpl withManagementCluster(ManagementCluster managementCluster) {
        if (isInCreateMode()) {
            this.innerModel().withManagementCluster(managementCluster);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withManagementCluster(managementCluster);
            return this;
        }
    }

    public PrivateCloudImpl withInternet(InternetEnum internet) {
        if (isInCreateMode()) {
            this.innerModel().withInternet(internet);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withInternet(internet);
            return this;
        }
    }

    public PrivateCloudImpl withIdentitySources(List<IdentitySource> identitySources) {
        if (isInCreateMode()) {
            this.innerModel().withIdentitySources(identitySources);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withIdentitySources(identitySources);
            return this;
        }
    }

    public PrivateCloudImpl withAvailability(AvailabilityProperties availability) {
        this.innerModel().withAvailability(availability);
        return this;
    }

    public PrivateCloudImpl withEncryption(Encryption encryption) {
        if (isInCreateMode()) {
            this.innerModel().withEncryption(encryption);
            return this;
        } else {
            this.updatePrivateCloudUpdate.withEncryption(encryption);
            return this;
        }
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}
