// 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.CloudServicesNetworkInner;
import com.azure.resourcemanager.networkcloud.models.CloudServicesNetwork;
import com.azure.resourcemanager.networkcloud.models.CloudServicesNetworkDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.CloudServicesNetworkEnableDefaultEgressEndpoints;
import com.azure.resourcemanager.networkcloud.models.CloudServicesNetworkPatchParameters;
import com.azure.resourcemanager.networkcloud.models.CloudServicesNetworkProvisioningState;
import com.azure.resourcemanager.networkcloud.models.EgressEndpoint;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class CloudServicesNetworkImpl
    implements CloudServicesNetwork, CloudServicesNetwork.Definition, CloudServicesNetwork.Update {
    private CloudServicesNetworkInner 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 List<EgressEndpoint> additionalEgressEndpoints() {
        List<EgressEndpoint> inner = this.innerModel().additionalEgressEndpoints();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

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

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

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

    public CloudServicesNetworkEnableDefaultEgressEndpoints enableDefaultEgressEndpoints() {
        return this.innerModel().enableDefaultEgressEndpoints();
    }

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

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

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

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

    public List<String> virtualMachinesAssociatedIds() {
        List<String> inner = this.innerModel().virtualMachinesAssociatedIds();
        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 CloudServicesNetworkInner innerModel() {
        return this.innerObject;
    }

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

    private String resourceGroupName;

    private String cloudServicesNetworkName;

    private CloudServicesNetworkPatchParameters updateCloudServicesNetworkUpdateParameters;

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

    public CloudServicesNetwork create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .createOrUpdate(resourceGroupName, cloudServicesNetworkName, this.innerModel(), Context.NONE);
        return this;
    }

    public CloudServicesNetwork create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .createOrUpdate(resourceGroupName, cloudServicesNetworkName, this.innerModel(), context);
        return this;
    }

    CloudServicesNetworkImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new CloudServicesNetworkInner();
        this.serviceManager = serviceManager;
        this.cloudServicesNetworkName = name;
    }

    public CloudServicesNetworkImpl update() {
        this.updateCloudServicesNetworkUpdateParameters = new CloudServicesNetworkPatchParameters();
        return this;
    }

    public CloudServicesNetwork apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .update(
                    resourceGroupName,
                    cloudServicesNetworkName,
                    updateCloudServicesNetworkUpdateParameters,
                    Context.NONE);
        return this;
    }

    public CloudServicesNetwork apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .update(
                    resourceGroupName, cloudServicesNetworkName, updateCloudServicesNetworkUpdateParameters, context);
        return this;
    }

    CloudServicesNetworkImpl(
        CloudServicesNetworkInner innerObject,
        com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.cloudServicesNetworkName = Utils.getValueFromIdByName(innerObject.id(), "cloudServicesNetworks");
    }

    public CloudServicesNetwork refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .getByResourceGroupWithResponse(resourceGroupName, cloudServicesNetworkName, Context.NONE)
                .getValue();
        return this;
    }

    public CloudServicesNetwork refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getCloudServicesNetworks()
                .getByResourceGroupWithResponse(resourceGroupName, cloudServicesNetworkName, context)
                .getValue();
        return this;
    }

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

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

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

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

    public CloudServicesNetworkImpl withAdditionalEgressEndpoints(List<EgressEndpoint> additionalEgressEndpoints) {
        if (isInCreateMode()) {
            this.innerModel().withAdditionalEgressEndpoints(additionalEgressEndpoints);
            return this;
        } else {
            this.updateCloudServicesNetworkUpdateParameters.withAdditionalEgressEndpoints(additionalEgressEndpoints);
            return this;
        }
    }

    public CloudServicesNetworkImpl withEnableDefaultEgressEndpoints(
        CloudServicesNetworkEnableDefaultEgressEndpoints enableDefaultEgressEndpoints) {
        if (isInCreateMode()) {
            this.innerModel().withEnableDefaultEgressEndpoints(enableDefaultEgressEndpoints);
            return this;
        } else {
            this
                .updateCloudServicesNetworkUpdateParameters
                .withEnableDefaultEgressEndpoints(enableDefaultEgressEndpoints);
            return this;
        }
    }

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