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

package com.azure.resourcemanager.managednetworkfabric.implementation;

import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.InternalNetworkInner;
import com.azure.resourcemanager.managednetworkfabric.models.BgpConfiguration;
import com.azure.resourcemanager.managednetworkfabric.models.ConnectedSubnet;
import com.azure.resourcemanager.managednetworkfabric.models.EnableDisableOnResources;
import com.azure.resourcemanager.managednetworkfabric.models.EnabledDisabledState;
import com.azure.resourcemanager.managednetworkfabric.models.InternalNetwork;
import com.azure.resourcemanager.managednetworkfabric.models.InternalNetworkPatch;
import com.azure.resourcemanager.managednetworkfabric.models.ProvisioningState;
import com.azure.resourcemanager.managednetworkfabric.models.StaticRouteConfiguration;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateAdministrativeState;
import java.util.Collections;
import java.util.List;

public final class InternalNetworkImpl implements InternalNetwork, InternalNetwork.Definition, InternalNetwork.Update {
    private InternalNetworkInner innerObject;

    private final com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager;

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

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

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

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

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

    public EnabledDisabledState administrativeState() {
        return this.innerModel().administrativeState();
    }

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

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

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

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

    public int vlanId() {
        return this.innerModel().vlanId();
    }

    public Integer mtu() {
        return this.innerModel().mtu();
    }

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

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

    public StaticRouteConfiguration staticRouteConfiguration() {
        return this.innerModel().staticRouteConfiguration();
    }

    public BgpConfiguration bgpConfiguration() {
        return this.innerModel().bgpConfiguration();
    }

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String l3IsolationDomainName;

    private String internalNetworkName;

    private InternalNetworkPatch updateBody;

    public InternalNetworkImpl withExistingL3IsolationDomain(String resourceGroupName, String l3IsolationDomainName) {
        this.resourceGroupName = resourceGroupName;
        this.l3IsolationDomainName = l3IsolationDomainName;
        return this;
    }

    public InternalNetwork create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .create(resourceGroupName, l3IsolationDomainName, internalNetworkName, this.innerModel(), Context.NONE);
        return this;
    }

    public InternalNetwork create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .create(resourceGroupName, l3IsolationDomainName, internalNetworkName, this.innerModel(), context);
        return this;
    }

    InternalNetworkImpl(
        String name, com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = new InternalNetworkInner();
        this.serviceManager = serviceManager;
        this.internalNetworkName = name;
    }

    public InternalNetworkImpl update() {
        this.updateBody = new InternalNetworkPatch();
        return this;
    }

    public InternalNetwork apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .update(resourceGroupName, l3IsolationDomainName, internalNetworkName, updateBody, Context.NONE);
        return this;
    }

    public InternalNetwork apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .update(resourceGroupName, l3IsolationDomainName, internalNetworkName, updateBody, context);
        return this;
    }

    InternalNetworkImpl(
        InternalNetworkInner innerObject,
        com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.l3IsolationDomainName = Utils.getValueFromIdByName(innerObject.id(), "l3IsolationDomains");
        this.internalNetworkName = Utils.getValueFromIdByName(innerObject.id(), "internalNetworks");
    }

    public InternalNetwork refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .getWithResponse(resourceGroupName, l3IsolationDomainName, internalNetworkName, Context.NONE)
                .getValue();
        return this;
    }

    public InternalNetwork refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getInternalNetworks()
                .getWithResponse(resourceGroupName, l3IsolationDomainName, internalNetworkName, context)
                .getValue();
        return this;
    }

    public void updateAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .internalNetworks()
            .updateAdministrativeState(resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void updateAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .internalNetworks()
            .updateAdministrativeState(resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public void updateBgpAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .internalNetworks()
            .updateBgpAdministrativeState(resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void updateBgpAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .internalNetworks()
            .updateBgpAdministrativeState(resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public void updateBfdForBgpAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .internalNetworks()
            .updateBfdForBgpAdministrativeState(resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void updateBfdForBgpAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .internalNetworks()
            .updateBfdForBgpAdministrativeState(
                resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public void clearIpv6Neighbors(EnableDisableOnResources body) {
        serviceManager
            .internalNetworks()
            .clearIpv6Neighbors(resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void clearIpv6Neighbors(EnableDisableOnResources body, Context context) {
        serviceManager
            .internalNetworks()
            .clearIpv6Neighbors(resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public void clearArpEntries(EnableDisableOnResources body) {
        serviceManager
            .internalNetworks()
            .clearArpEntries(resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void clearArpEntries(EnableDisableOnResources body, Context context) {
        serviceManager
            .internalNetworks()
            .clearArpEntries(resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public void updateBfdForStaticRouteAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .internalNetworks()
            .updateBfdForStaticRouteAdministrativeState(
                resourceGroupName, l3IsolationDomainName, internalNetworkName, body);
    }

    public void updateBfdForStaticRouteAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .internalNetworks()
            .updateBfdForStaticRouteAdministrativeState(
                resourceGroupName, l3IsolationDomainName, internalNetworkName, body, context);
    }

    public InternalNetworkImpl withVlanId(int vlanId) {
        this.innerModel().withVlanId(vlanId);
        return this;
    }

    public InternalNetworkImpl withMtu(Integer mtu) {
        if (isInCreateMode()) {
            this.innerModel().withMtu(mtu);
            return this;
        } else {
            this.updateBody.withMtu(mtu);
            return this;
        }
    }

    public InternalNetworkImpl withConnectedIPv4Subnets(List<ConnectedSubnet> connectedIPv4Subnets) {
        if (isInCreateMode()) {
            this.innerModel().withConnectedIPv4Subnets(connectedIPv4Subnets);
            return this;
        } else {
            this.updateBody.withConnectedIPv4Subnets(connectedIPv4Subnets);
            return this;
        }
    }

    public InternalNetworkImpl withConnectedIPv6Subnets(List<ConnectedSubnet> connectedIPv6Subnets) {
        if (isInCreateMode()) {
            this.innerModel().withConnectedIPv6Subnets(connectedIPv6Subnets);
            return this;
        } else {
            this.updateBody.withConnectedIPv6Subnets(connectedIPv6Subnets);
            return this;
        }
    }

    public InternalNetworkImpl withStaticRouteConfiguration(StaticRouteConfiguration staticRouteConfiguration) {
        if (isInCreateMode()) {
            this.innerModel().withStaticRouteConfiguration(staticRouteConfiguration);
            return this;
        } else {
            this.updateBody.withStaticRouteConfiguration(staticRouteConfiguration);
            return this;
        }
    }

    public InternalNetworkImpl withBgpConfiguration(BgpConfiguration bgpConfiguration) {
        if (isInCreateMode()) {
            this.innerModel().withBgpConfiguration(bgpConfiguration);
            return this;
        } else {
            this.updateBody.withBgpConfiguration(bgpConfiguration);
            return this;
        }
    }

    public InternalNetworkImpl withImportRoutePolicyId(String importRoutePolicyId) {
        if (isInCreateMode()) {
            this.innerModel().withImportRoutePolicyId(importRoutePolicyId);
            return this;
        } else {
            this.updateBody.withImportRoutePolicyId(importRoutePolicyId);
            return this;
        }
    }

    public InternalNetworkImpl withExportRoutePolicyId(String exportRoutePolicyId) {
        if (isInCreateMode()) {
            this.innerModel().withExportRoutePolicyId(exportRoutePolicyId);
            return this;
        } else {
            this.updateBody.withExportRoutePolicyId(exportRoutePolicyId);
            return this;
        }
    }

    public InternalNetworkImpl withAnnotation(String annotation) {
        if (isInCreateMode()) {
            this.innerModel().withAnnotation(annotation);
            return this;
        } else {
            this.updateBody.withAnnotation(annotation);
            return this;
        }
    }

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