// 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.ExternalNetworkInner;
import com.azure.resourcemanager.managednetworkfabric.models.EnableDisableOnResources;
import com.azure.resourcemanager.managednetworkfabric.models.EnabledDisabledState;
import com.azure.resourcemanager.managednetworkfabric.models.ExternalNetwork;
import com.azure.resourcemanager.managednetworkfabric.models.ExternalNetworkPatch;
import com.azure.resourcemanager.managednetworkfabric.models.ExternalNetworkPropertiesOptionAProperties;
import com.azure.resourcemanager.managednetworkfabric.models.Layer3OptionAProperties;
import com.azure.resourcemanager.managednetworkfabric.models.OptionBProperties;
import com.azure.resourcemanager.managednetworkfabric.models.PeeringOption;
import com.azure.resourcemanager.managednetworkfabric.models.ProvisioningState;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateAdministrativeState;
import java.util.Collections;
import java.util.List;

public final class ExternalNetworkImpl implements ExternalNetwork, ExternalNetwork.Definition, ExternalNetwork.Update {
    private ExternalNetworkInner 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 String networkToNetworkInterconnectId() {
        return this.innerModel().networkToNetworkInterconnectId();
    }

    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 ProvisioningState provisioningState() {
        return this.innerModel().provisioningState();
    }

    public PeeringOption peeringOption() {
        return this.innerModel().peeringOption();
    }

    public OptionBProperties optionBProperties() {
        return this.innerModel().optionBProperties();
    }

    public ExternalNetworkPropertiesOptionAProperties optionAProperties() {
        return this.innerModel().optionAProperties();
    }

    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 ExternalNetworkInner innerModel() {
        return this.innerObject;
    }

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

    private String resourceGroupName;

    private String l3IsolationDomainName;

    private String externalNetworkName;

    private ExternalNetworkPatch updateBody;

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

    public ExternalNetwork create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .create(resourceGroupName, l3IsolationDomainName, externalNetworkName, this.innerModel(), Context.NONE);
        return this;
    }

    public ExternalNetwork create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .create(resourceGroupName, l3IsolationDomainName, externalNetworkName, this.innerModel(), context);
        return this;
    }

    ExternalNetworkImpl(
        String name, com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = new ExternalNetworkInner();
        this.serviceManager = serviceManager;
        this.externalNetworkName = name;
    }

    public ExternalNetworkImpl update() {
        this.updateBody = new ExternalNetworkPatch();
        return this;
    }

    public ExternalNetwork apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .update(resourceGroupName, l3IsolationDomainName, externalNetworkName, updateBody, Context.NONE);
        return this;
    }

    public ExternalNetwork apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .update(resourceGroupName, l3IsolationDomainName, externalNetworkName, updateBody, context);
        return this;
    }

    ExternalNetworkImpl(
        ExternalNetworkInner 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.externalNetworkName = Utils.getValueFromIdByName(innerObject.id(), "externalNetworks");
    }

    public ExternalNetwork refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .getWithResponse(resourceGroupName, l3IsolationDomainName, externalNetworkName, Context.NONE)
                .getValue();
        return this;
    }

    public ExternalNetwork refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getExternalNetworks()
                .getWithResponse(resourceGroupName, l3IsolationDomainName, externalNetworkName, context)
                .getValue();
        return this;
    }

    public void updateAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .externalNetworks()
            .updateAdministrativeState(resourceGroupName, l3IsolationDomainName, externalNetworkName, body);
    }

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

    public void updateBgpAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .externalNetworks()
            .updateBgpAdministrativeState(resourceGroupName, l3IsolationDomainName, externalNetworkName, body);
    }

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

    public void updateBfdForBgpAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .externalNetworks()
            .updateBfdForBgpAdministrativeState(resourceGroupName, l3IsolationDomainName, externalNetworkName, body);
    }

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

    public void clearIpv6Neighbors(EnableDisableOnResources body) {
        serviceManager
            .externalNetworks()
            .clearIpv6Neighbors(resourceGroupName, l3IsolationDomainName, externalNetworkName, body);
    }

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

    public void clearArpEntries(EnableDisableOnResources body) {
        serviceManager
            .externalNetworks()
            .clearArpEntries(resourceGroupName, l3IsolationDomainName, externalNetworkName, body);
    }

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

    public ExternalNetworkImpl withPeeringOption(PeeringOption peeringOption) {
        if (isInCreateMode()) {
            this.innerModel().withPeeringOption(peeringOption);
            return this;
        } else {
            this.updateBody.withPeeringOption(peeringOption);
            return this;
        }
    }

    public ExternalNetworkImpl withOptionBProperties(OptionBProperties optionBProperties) {
        if (isInCreateMode()) {
            this.innerModel().withOptionBProperties(optionBProperties);
            return this;
        } else {
            this.updateBody.withOptionBProperties(optionBProperties);
            return this;
        }
    }

    public ExternalNetworkImpl withOptionAProperties(ExternalNetworkPropertiesOptionAProperties optionAProperties) {
        this.innerModel().withOptionAProperties(optionAProperties);
        return this;
    }

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

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

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

    public ExternalNetworkImpl withOptionAProperties(Layer3OptionAProperties optionAProperties) {
        this.updateBody.withOptionAProperties(optionAProperties);
        return this;
    }

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