// 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.L3NetworkInner;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.HybridAksIpamEnabled;
import com.azure.resourcemanager.networkcloud.models.HybridAksPluginType;
import com.azure.resourcemanager.networkcloud.models.IpAllocationType;
import com.azure.resourcemanager.networkcloud.models.L3Network;
import com.azure.resourcemanager.networkcloud.models.L3NetworkDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.L3NetworkPatchParameters;
import com.azure.resourcemanager.networkcloud.models.L3NetworkProvisioningState;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class L3NetworkImpl implements L3Network, L3Network.Definition, L3Network.Update {
    private L3NetworkInner 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<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 L3NetworkDetailedStatus detailedStatus() {
        return this.innerModel().detailedStatus();
    }

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

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

    public HybridAksIpamEnabled hybridAksIpamEnabled() {
        return this.innerModel().hybridAksIpamEnabled();
    }

    public HybridAksPluginType hybridAksPluginType() {
        return this.innerModel().hybridAksPluginType();
    }

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

    public IpAllocationType ipAllocationType() {
        return this.innerModel().ipAllocationType();
    }

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

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

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

    public L3NetworkProvisioningState 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 long vlan() {
        return this.innerModel().vlan();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String l3NetworkName;

    private L3NetworkPatchParameters updateL3NetworkUpdateParameters;

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

    public L3Network create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .createOrUpdate(resourceGroupName, l3NetworkName, this.innerModel(), Context.NONE);
        return this;
    }

    public L3Network create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .createOrUpdate(resourceGroupName, l3NetworkName, this.innerModel(), context);
        return this;
    }

    L3NetworkImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new L3NetworkInner();
        this.serviceManager = serviceManager;
        this.l3NetworkName = name;
    }

    public L3NetworkImpl update() {
        this.updateL3NetworkUpdateParameters = new L3NetworkPatchParameters();
        return this;
    }

    public L3Network apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .updateWithResponse(resourceGroupName, l3NetworkName, updateL3NetworkUpdateParameters, Context.NONE)
                .getValue();
        return this;
    }

    public L3Network apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .updateWithResponse(resourceGroupName, l3NetworkName, updateL3NetworkUpdateParameters, context)
                .getValue();
        return this;
    }

    L3NetworkImpl(
        L3NetworkInner innerObject, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.l3NetworkName = Utils.getValueFromIdByName(innerObject.id(), "l3Networks");
    }

    public L3Network refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .getByResourceGroupWithResponse(resourceGroupName, l3NetworkName, Context.NONE)
                .getValue();
        return this;
    }

    public L3Network refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3Networks()
                .getByResourceGroupWithResponse(resourceGroupName, l3NetworkName, context)
                .getValue();
        return this;
    }

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

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

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

    public L3NetworkImpl withL3IsolationDomainId(String l3IsolationDomainId) {
        this.innerModel().withL3IsolationDomainId(l3IsolationDomainId);
        return this;
    }

    public L3NetworkImpl withVlan(long vlan) {
        this.innerModel().withVlan(vlan);
        return this;
    }

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

    public L3NetworkImpl withHybridAksIpamEnabled(HybridAksIpamEnabled hybridAksIpamEnabled) {
        this.innerModel().withHybridAksIpamEnabled(hybridAksIpamEnabled);
        return this;
    }

    public L3NetworkImpl withHybridAksPluginType(HybridAksPluginType hybridAksPluginType) {
        this.innerModel().withHybridAksPluginType(hybridAksPluginType);
        return this;
    }

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

    public L3NetworkImpl withIpAllocationType(IpAllocationType ipAllocationType) {
        this.innerModel().withIpAllocationType(ipAllocationType);
        return this;
    }

    public L3NetworkImpl withIpv4ConnectedPrefix(String ipv4ConnectedPrefix) {
        this.innerModel().withIpv4ConnectedPrefix(ipv4ConnectedPrefix);
        return this;
    }

    public L3NetworkImpl withIpv6ConnectedPrefix(String ipv6ConnectedPrefix) {
        this.innerModel().withIpv6ConnectedPrefix(ipv6ConnectedPrefix);
        return this;
    }

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