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

package com.azure.resourcemanager.servicefabric.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.servicefabric.fluent.models.ClusterInner;
import com.azure.resourcemanager.servicefabric.fluent.models.ClusterVersionDetails;
import com.azure.resourcemanager.servicefabric.models.AddOnFeatures;
import com.azure.resourcemanager.servicefabric.models.ApplicationTypeVersionsCleanupPolicy;
import com.azure.resourcemanager.servicefabric.models.AzureActiveDirectory;
import com.azure.resourcemanager.servicefabric.models.CertificateDescription;
import com.azure.resourcemanager.servicefabric.models.ClientCertificateCommonName;
import com.azure.resourcemanager.servicefabric.models.ClientCertificateThumbprint;
import com.azure.resourcemanager.servicefabric.models.Cluster;
import com.azure.resourcemanager.servicefabric.models.ClusterState;
import com.azure.resourcemanager.servicefabric.models.ClusterUpdateParameters;
import com.azure.resourcemanager.servicefabric.models.ClusterUpgradeCadence;
import com.azure.resourcemanager.servicefabric.models.ClusterUpgradePolicy;
import com.azure.resourcemanager.servicefabric.models.DiagnosticsStorageAccountConfig;
import com.azure.resourcemanager.servicefabric.models.NodeTypeDescription;
import com.azure.resourcemanager.servicefabric.models.Notification;
import com.azure.resourcemanager.servicefabric.models.ProvisioningState;
import com.azure.resourcemanager.servicefabric.models.ReliabilityLevel;
import com.azure.resourcemanager.servicefabric.models.ServerCertificateCommonNames;
import com.azure.resourcemanager.servicefabric.models.SettingsSectionDescription;
import com.azure.resourcemanager.servicefabric.models.SfZonalUpgradeMode;
import com.azure.resourcemanager.servicefabric.models.UpgradableVersionPathResult;
import com.azure.resourcemanager.servicefabric.models.UpgradableVersionsDescription;
import com.azure.resourcemanager.servicefabric.models.UpgradeMode;
import com.azure.resourcemanager.servicefabric.models.VmssZonalUpgradeMode;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class ClusterImpl implements Cluster, Cluster.Definition, Cluster.Update {
    private ClusterInner innerObject;

    private final com.azure.resourcemanager.servicefabric.ServiceFabricManager 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 String etag() {
        return this.innerModel().etag();
    }

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

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

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

    public AzureActiveDirectory azureActiveDirectory() {
        return this.innerModel().azureActiveDirectory();
    }

    public CertificateDescription certificate() {
        return this.innerModel().certificate();
    }

    public ServerCertificateCommonNames certificateCommonNames() {
        return this.innerModel().certificateCommonNames();
    }

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

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

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

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

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

    public ClusterState clusterState() {
        return this.innerModel().clusterState();
    }

    public DiagnosticsStorageAccountConfig diagnosticsStorageAccountConfig() {
        return this.innerModel().diagnosticsStorageAccountConfig();
    }

    public Boolean eventStoreServiceEnabled() {
        return this.innerModel().eventStoreServiceEnabled();
    }

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

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

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

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

    public ReliabilityLevel reliabilityLevel() {
        return this.innerModel().reliabilityLevel();
    }

    public CertificateDescription reverseProxyCertificate() {
        return this.innerModel().reverseProxyCertificate();
    }

    public ServerCertificateCommonNames reverseProxyCertificateCommonNames() {
        return this.innerModel().reverseProxyCertificateCommonNames();
    }

    public ClusterUpgradePolicy upgradeDescription() {
        return this.innerModel().upgradeDescription();
    }

    public UpgradeMode upgradeMode() {
        return this.innerModel().upgradeMode();
    }

    public ApplicationTypeVersionsCleanupPolicy applicationTypeVersionsCleanupPolicy() {
        return this.innerModel().applicationTypeVersionsCleanupPolicy();
    }

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

    public SfZonalUpgradeMode sfZonalUpgradeMode() {
        return this.innerModel().sfZonalUpgradeMode();
    }

    public VmssZonalUpgradeMode vmssZonalUpgradeMode() {
        return this.innerModel().vmssZonalUpgradeMode();
    }

    public Boolean infrastructureServiceManager() {
        return this.innerModel().infrastructureServiceManager();
    }

    public ClusterUpgradeCadence upgradeWave() {
        return this.innerModel().upgradeWave();
    }

    public OffsetDateTime upgradePauseStartTimestampUtc() {
        return this.innerModel().upgradePauseStartTimestampUtc();
    }

    public OffsetDateTime upgradePauseEndTimestampUtc() {
        return this.innerModel().upgradePauseEndTimestampUtc();
    }

    public Boolean waveUpgradePaused() {
        return this.innerModel().waveUpgradePaused();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.servicefabric.ServiceFabricManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String clusterName;

    private ClusterUpdateParameters updateParameters;

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

    public Cluster create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .createOrUpdate(resourceGroupName, clusterName, this.innerModel(), Context.NONE);
        return this;
    }

    public Cluster create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .createOrUpdate(resourceGroupName, clusterName, this.innerModel(), context);
        return this;
    }

    ClusterImpl(String name, com.azure.resourcemanager.servicefabric.ServiceFabricManager serviceManager) {
        this.innerObject = new ClusterInner();
        this.serviceManager = serviceManager;
        this.clusterName = name;
    }

    public ClusterImpl update() {
        this.updateParameters = new ClusterUpdateParameters();
        return this;
    }

    public Cluster apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .update(resourceGroupName, clusterName, updateParameters, Context.NONE);
        return this;
    }

    public Cluster apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .update(resourceGroupName, clusterName, updateParameters, context);
        return this;
    }

    ClusterImpl(ClusterInner innerObject, com.azure.resourcemanager.servicefabric.ServiceFabricManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.clusterName = Utils.getValueFromIdByName(innerObject.id(), "clusters");
    }

    public Cluster refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .getByResourceGroupWithResponse(resourceGroupName, clusterName, Context.NONE)
                .getValue();
        return this;
    }

    public Cluster refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getClusters()
                .getByResourceGroupWithResponse(resourceGroupName, clusterName, context)
                .getValue();
        return this;
    }

    public Response<UpgradableVersionPathResult> listUpgradableVersionsWithResponse(
        UpgradableVersionsDescription versionsDescription, Context context) {
        return serviceManager
            .clusters()
            .listUpgradableVersionsWithResponse(resourceGroupName, clusterName, versionsDescription, context);
    }

    public UpgradableVersionPathResult listUpgradableVersions() {
        return serviceManager.clusters().listUpgradableVersions(resourceGroupName, clusterName);
    }

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

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

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

    public ClusterImpl withAddOnFeatures(List<AddOnFeatures> addOnFeatures) {
        if (isInCreateMode()) {
            this.innerModel().withAddOnFeatures(addOnFeatures);
            return this;
        } else {
            this.updateParameters.withAddOnFeatures(addOnFeatures);
            return this;
        }
    }

    public ClusterImpl withAzureActiveDirectory(AzureActiveDirectory azureActiveDirectory) {
        this.innerModel().withAzureActiveDirectory(azureActiveDirectory);
        return this;
    }

    public ClusterImpl withCertificate(CertificateDescription certificate) {
        if (isInCreateMode()) {
            this.innerModel().withCertificate(certificate);
            return this;
        } else {
            this.updateParameters.withCertificate(certificate);
            return this;
        }
    }

    public ClusterImpl withCertificateCommonNames(ServerCertificateCommonNames certificateCommonNames) {
        if (isInCreateMode()) {
            this.innerModel().withCertificateCommonNames(certificateCommonNames);
            return this;
        } else {
            this.updateParameters.withCertificateCommonNames(certificateCommonNames);
            return this;
        }
    }

    public ClusterImpl withClientCertificateCommonNames(
        List<ClientCertificateCommonName> clientCertificateCommonNames) {
        if (isInCreateMode()) {
            this.innerModel().withClientCertificateCommonNames(clientCertificateCommonNames);
            return this;
        } else {
            this.updateParameters.withClientCertificateCommonNames(clientCertificateCommonNames);
            return this;
        }
    }

    public ClusterImpl withClientCertificateThumbprints(
        List<ClientCertificateThumbprint> clientCertificateThumbprints) {
        if (isInCreateMode()) {
            this.innerModel().withClientCertificateThumbprints(clientCertificateThumbprints);
            return this;
        } else {
            this.updateParameters.withClientCertificateThumbprints(clientCertificateThumbprints);
            return this;
        }
    }

    public ClusterImpl withClusterCodeVersion(String clusterCodeVersion) {
        if (isInCreateMode()) {
            this.innerModel().withClusterCodeVersion(clusterCodeVersion);
            return this;
        } else {
            this.updateParameters.withClusterCodeVersion(clusterCodeVersion);
            return this;
        }
    }

    public ClusterImpl withDiagnosticsStorageAccountConfig(
        DiagnosticsStorageAccountConfig diagnosticsStorageAccountConfig) {
        this.innerModel().withDiagnosticsStorageAccountConfig(diagnosticsStorageAccountConfig);
        return this;
    }

    public ClusterImpl withEventStoreServiceEnabled(Boolean eventStoreServiceEnabled) {
        if (isInCreateMode()) {
            this.innerModel().withEventStoreServiceEnabled(eventStoreServiceEnabled);
            return this;
        } else {
            this.updateParameters.withEventStoreServiceEnabled(eventStoreServiceEnabled);
            return this;
        }
    }

    public ClusterImpl withFabricSettings(List<SettingsSectionDescription> fabricSettings) {
        if (isInCreateMode()) {
            this.innerModel().withFabricSettings(fabricSettings);
            return this;
        } else {
            this.updateParameters.withFabricSettings(fabricSettings);
            return this;
        }
    }

    public ClusterImpl withManagementEndpoint(String managementEndpoint) {
        this.innerModel().withManagementEndpoint(managementEndpoint);
        return this;
    }

    public ClusterImpl withNodeTypes(List<NodeTypeDescription> nodeTypes) {
        if (isInCreateMode()) {
            this.innerModel().withNodeTypes(nodeTypes);
            return this;
        } else {
            this.updateParameters.withNodeTypes(nodeTypes);
            return this;
        }
    }

    public ClusterImpl withReliabilityLevel(ReliabilityLevel reliabilityLevel) {
        if (isInCreateMode()) {
            this.innerModel().withReliabilityLevel(reliabilityLevel);
            return this;
        } else {
            this.updateParameters.withReliabilityLevel(reliabilityLevel);
            return this;
        }
    }

    public ClusterImpl withReverseProxyCertificate(CertificateDescription reverseProxyCertificate) {
        if (isInCreateMode()) {
            this.innerModel().withReverseProxyCertificate(reverseProxyCertificate);
            return this;
        } else {
            this.updateParameters.withReverseProxyCertificate(reverseProxyCertificate);
            return this;
        }
    }

    public ClusterImpl withReverseProxyCertificateCommonNames(
        ServerCertificateCommonNames reverseProxyCertificateCommonNames) {
        this.innerModel().withReverseProxyCertificateCommonNames(reverseProxyCertificateCommonNames);
        return this;
    }

    public ClusterImpl withUpgradeDescription(ClusterUpgradePolicy upgradeDescription) {
        if (isInCreateMode()) {
            this.innerModel().withUpgradeDescription(upgradeDescription);
            return this;
        } else {
            this.updateParameters.withUpgradeDescription(upgradeDescription);
            return this;
        }
    }

    public ClusterImpl withUpgradeMode(UpgradeMode upgradeMode) {
        if (isInCreateMode()) {
            this.innerModel().withUpgradeMode(upgradeMode);
            return this;
        } else {
            this.updateParameters.withUpgradeMode(upgradeMode);
            return this;
        }
    }

    public ClusterImpl withApplicationTypeVersionsCleanupPolicy(
        ApplicationTypeVersionsCleanupPolicy applicationTypeVersionsCleanupPolicy) {
        if (isInCreateMode()) {
            this.innerModel().withApplicationTypeVersionsCleanupPolicy(applicationTypeVersionsCleanupPolicy);
            return this;
        } else {
            this.updateParameters.withApplicationTypeVersionsCleanupPolicy(applicationTypeVersionsCleanupPolicy);
            return this;
        }
    }

    public ClusterImpl withVmImage(String vmImage) {
        this.innerModel().withVmImage(vmImage);
        return this;
    }

    public ClusterImpl withSfZonalUpgradeMode(SfZonalUpgradeMode sfZonalUpgradeMode) {
        if (isInCreateMode()) {
            this.innerModel().withSfZonalUpgradeMode(sfZonalUpgradeMode);
            return this;
        } else {
            this.updateParameters.withSfZonalUpgradeMode(sfZonalUpgradeMode);
            return this;
        }
    }

    public ClusterImpl withVmssZonalUpgradeMode(VmssZonalUpgradeMode vmssZonalUpgradeMode) {
        if (isInCreateMode()) {
            this.innerModel().withVmssZonalUpgradeMode(vmssZonalUpgradeMode);
            return this;
        } else {
            this.updateParameters.withVmssZonalUpgradeMode(vmssZonalUpgradeMode);
            return this;
        }
    }

    public ClusterImpl withInfrastructureServiceManager(Boolean infrastructureServiceManager) {
        if (isInCreateMode()) {
            this.innerModel().withInfrastructureServiceManager(infrastructureServiceManager);
            return this;
        } else {
            this.updateParameters.withInfrastructureServiceManager(infrastructureServiceManager);
            return this;
        }
    }

    public ClusterImpl withUpgradeWave(ClusterUpgradeCadence upgradeWave) {
        if (isInCreateMode()) {
            this.innerModel().withUpgradeWave(upgradeWave);
            return this;
        } else {
            this.updateParameters.withUpgradeWave(upgradeWave);
            return this;
        }
    }

    public ClusterImpl withUpgradePauseStartTimestampUtc(OffsetDateTime upgradePauseStartTimestampUtc) {
        if (isInCreateMode()) {
            this.innerModel().withUpgradePauseStartTimestampUtc(upgradePauseStartTimestampUtc);
            return this;
        } else {
            this.updateParameters.withUpgradePauseStartTimestampUtc(upgradePauseStartTimestampUtc);
            return this;
        }
    }

    public ClusterImpl withUpgradePauseEndTimestampUtc(OffsetDateTime upgradePauseEndTimestampUtc) {
        if (isInCreateMode()) {
            this.innerModel().withUpgradePauseEndTimestampUtc(upgradePauseEndTimestampUtc);
            return this;
        } else {
            this.updateParameters.withUpgradePauseEndTimestampUtc(upgradePauseEndTimestampUtc);
            return this;
        }
    }

    public ClusterImpl withWaveUpgradePaused(Boolean waveUpgradePaused) {
        if (isInCreateMode()) {
            this.innerModel().withWaveUpgradePaused(waveUpgradePaused);
            return this;
        } else {
            this.updateParameters.withWaveUpgradePaused(waveUpgradePaused);
            return this;
        }
    }

    public ClusterImpl withNotifications(List<Notification> notifications) {
        if (isInCreateMode()) {
            this.innerModel().withNotifications(notifications);
            return this;
        } else {
            this.updateParameters.withNotifications(notifications);
            return this;
        }
    }

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