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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.networkcloud.fluent.models.KubernetesClusterInner;
import com.azure.resourcemanager.networkcloud.models.AadConfiguration;
import com.azure.resourcemanager.networkcloud.models.AdministratorConfiguration;
import com.azure.resourcemanager.networkcloud.models.AvailableUpgrade;
import com.azure.resourcemanager.networkcloud.models.ControlPlaneNodeConfiguration;
import com.azure.resourcemanager.networkcloud.models.ControlPlaneNodePatchConfiguration;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.FeatureStatus;
import com.azure.resourcemanager.networkcloud.models.InitialAgentPoolConfiguration;
import com.azure.resourcemanager.networkcloud.models.KubernetesCluster;
import com.azure.resourcemanager.networkcloud.models.KubernetesClusterDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.KubernetesClusterNode;
import com.azure.resourcemanager.networkcloud.models.KubernetesClusterPatchParameters;
import com.azure.resourcemanager.networkcloud.models.KubernetesClusterProvisioningState;
import com.azure.resourcemanager.networkcloud.models.KubernetesClusterRestartNodeParameters;
import com.azure.resourcemanager.networkcloud.models.ManagedResourceGroupConfiguration;
import com.azure.resourcemanager.networkcloud.models.NetworkConfiguration;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class KubernetesClusterImpl
    implements KubernetesCluster, KubernetesCluster.Definition, KubernetesCluster.Update {
    private KubernetesClusterInner innerObject;

    private final com.azure.resourcemanager.networkcloud.NetworkCloudManager 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 ExtendedLocation extendedLocation() {
        return this.innerModel().extendedLocation();
    }

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

    public AadConfiguration aadConfiguration() {
        return this.innerModel().aadConfiguration();
    }

    public AdministratorConfiguration administratorConfiguration() {
        return this.innerModel().administratorConfiguration();
    }

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

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

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

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

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

    public ControlPlaneNodeConfiguration controlPlaneNodeConfiguration() {
        return this.innerModel().controlPlaneNodeConfiguration();
    }

    public KubernetesClusterDetailedStatus detailedStatus() {
        return this.innerModel().detailedStatus();
    }

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

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

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

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

    public ManagedResourceGroupConfiguration managedResourceGroupConfiguration() {
        return this.innerModel().managedResourceGroupConfiguration();
    }

    public NetworkConfiguration networkConfiguration() {
        return this.innerModel().networkConfiguration();
    }

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.networkcloud.NetworkCloudManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String kubernetesClusterName;

    private KubernetesClusterPatchParameters updateKubernetesClusterUpdateParameters;

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

    public KubernetesCluster create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .createOrUpdate(resourceGroupName, kubernetesClusterName, this.innerModel(), Context.NONE);
        return this;
    }

    public KubernetesCluster create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .createOrUpdate(resourceGroupName, kubernetesClusterName, this.innerModel(), context);
        return this;
    }

    KubernetesClusterImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new KubernetesClusterInner();
        this.serviceManager = serviceManager;
        this.kubernetesClusterName = name;
    }

    public KubernetesClusterImpl update() {
        this.updateKubernetesClusterUpdateParameters = new KubernetesClusterPatchParameters();
        return this;
    }

    public KubernetesCluster apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .update(
                    resourceGroupName, kubernetesClusterName, updateKubernetesClusterUpdateParameters, Context.NONE);
        return this;
    }

    public KubernetesCluster apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .update(resourceGroupName, kubernetesClusterName, updateKubernetesClusterUpdateParameters, context);
        return this;
    }

    KubernetesClusterImpl(
        KubernetesClusterInner innerObject, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.kubernetesClusterName = Utils.getValueFromIdByName(innerObject.id(), "kubernetesClusters");
    }

    public KubernetesCluster refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .getByResourceGroupWithResponse(resourceGroupName, kubernetesClusterName, Context.NONE)
                .getValue();
        return this;
    }

    public KubernetesCluster refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getKubernetesClusters()
                .getByResourceGroupWithResponse(resourceGroupName, kubernetesClusterName, context)
                .getValue();
        return this;
    }

    public void restartNode(KubernetesClusterRestartNodeParameters kubernetesClusterRestartNodeParameters) {
        serviceManager
            .kubernetesClusters()
            .restartNode(resourceGroupName, kubernetesClusterName, kubernetesClusterRestartNodeParameters);
    }

    public void restartNode(
        KubernetesClusterRestartNodeParameters kubernetesClusterRestartNodeParameters, Context context) {
        serviceManager
            .kubernetesClusters()
            .restartNode(resourceGroupName, kubernetesClusterName, kubernetesClusterRestartNodeParameters, context);
    }

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

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

    public KubernetesClusterImpl withExtendedLocation(ExtendedLocation extendedLocation) {
        this.innerModel().withExtendedLocation(extendedLocation);
        return this;
    }

    public KubernetesClusterImpl withControlPlaneNodeConfiguration(
        ControlPlaneNodeConfiguration controlPlaneNodeConfiguration) {
        this.innerModel().withControlPlaneNodeConfiguration(controlPlaneNodeConfiguration);
        return this;
    }

    public KubernetesClusterImpl withInitialAgentPoolConfigurations(
        List<InitialAgentPoolConfiguration> initialAgentPoolConfigurations) {
        this.innerModel().withInitialAgentPoolConfigurations(initialAgentPoolConfigurations);
        return this;
    }

    public KubernetesClusterImpl withKubernetesVersion(String kubernetesVersion) {
        if (isInCreateMode()) {
            this.innerModel().withKubernetesVersion(kubernetesVersion);
            return this;
        } else {
            this.updateKubernetesClusterUpdateParameters.withKubernetesVersion(kubernetesVersion);
            return this;
        }
    }

    public KubernetesClusterImpl withNetworkConfiguration(NetworkConfiguration networkConfiguration) {
        this.innerModel().withNetworkConfiguration(networkConfiguration);
        return this;
    }

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

    public KubernetesClusterImpl withAadConfiguration(AadConfiguration aadConfiguration) {
        this.innerModel().withAadConfiguration(aadConfiguration);
        return this;
    }

    public KubernetesClusterImpl withAdministratorConfiguration(AdministratorConfiguration administratorConfiguration) {
        this.innerModel().withAdministratorConfiguration(administratorConfiguration);
        return this;
    }

    public KubernetesClusterImpl withManagedResourceGroupConfiguration(
        ManagedResourceGroupConfiguration managedResourceGroupConfiguration) {
        this.innerModel().withManagedResourceGroupConfiguration(managedResourceGroupConfiguration);
        return this;
    }

    public KubernetesClusterImpl withControlPlaneNodeConfiguration(
        ControlPlaneNodePatchConfiguration controlPlaneNodeConfiguration) {
        this.updateKubernetesClusterUpdateParameters.withControlPlaneNodeConfiguration(controlPlaneNodeConfiguration);
        return this;
    }

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