// 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.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.L2IsolationDomainInner;
import com.azure.resourcemanager.managednetworkfabric.models.ArpProperties;
import com.azure.resourcemanager.managednetworkfabric.models.EnableDisableOnResources;
import com.azure.resourcemanager.managednetworkfabric.models.EnabledDisabledState;
import com.azure.resourcemanager.managednetworkfabric.models.L2IsolationDomain;
import com.azure.resourcemanager.managednetworkfabric.models.L2IsolationDomainPatch;
import com.azure.resourcemanager.managednetworkfabric.models.ProvisioningState;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateAdministrativeState;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class L2IsolationDomainImpl
    implements L2IsolationDomain, L2IsolationDomain.Definition, L2IsolationDomain.Update {
    private L2IsolationDomainInner 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 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 SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

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

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

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String l2IsolationDomainName;

    private L2IsolationDomainPatch updateBody;

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

    public L2IsolationDomain create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .create(resourceGroupName, l2IsolationDomainName, this.innerModel(), Context.NONE);
        return this;
    }

    public L2IsolationDomain create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .create(resourceGroupName, l2IsolationDomainName, this.innerModel(), context);
        return this;
    }

    L2IsolationDomainImpl(
        String name, com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = new L2IsolationDomainInner();
        this.serviceManager = serviceManager;
        this.l2IsolationDomainName = name;
    }

    public L2IsolationDomainImpl update() {
        this.updateBody = new L2IsolationDomainPatch();
        return this;
    }

    public L2IsolationDomain apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .update(resourceGroupName, l2IsolationDomainName, updateBody, Context.NONE);
        return this;
    }

    public L2IsolationDomain apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .update(resourceGroupName, l2IsolationDomainName, updateBody, context);
        return this;
    }

    L2IsolationDomainImpl(
        L2IsolationDomainInner innerObject,
        com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.l2IsolationDomainName = Utils.getValueFromIdByName(innerObject.id(), "l2IsolationDomains");
    }

    public L2IsolationDomain refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .getByResourceGroupWithResponse(resourceGroupName, l2IsolationDomainName, Context.NONE)
                .getValue();
        return this;
    }

    public L2IsolationDomain refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL2IsolationDomains()
                .getByResourceGroupWithResponse(resourceGroupName, l2IsolationDomainName, context)
                .getValue();
        return this;
    }

    public void updateAdministrativeState(UpdateAdministrativeState body) {
        serviceManager.l2IsolationDomains().updateAdministrativeState(resourceGroupName, l2IsolationDomainName, body);
    }

    public void updateAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .l2IsolationDomains()
            .updateAdministrativeState(resourceGroupName, l2IsolationDomainName, body, context);
    }

    public void clearArpTable(EnableDisableOnResources body) {
        serviceManager.l2IsolationDomains().clearArpTable(resourceGroupName, l2IsolationDomainName, body);
    }

    public void clearArpTable(EnableDisableOnResources body, Context context) {
        serviceManager.l2IsolationDomains().clearArpTable(resourceGroupName, l2IsolationDomainName, body, context);
    }

    public void clearNeighborTable(EnableDisableOnResources body) {
        serviceManager.l2IsolationDomains().clearNeighborTable(resourceGroupName, l2IsolationDomainName, body);
    }

    public void clearNeighborTable(EnableDisableOnResources body, Context context) {
        serviceManager.l2IsolationDomains().clearNeighborTable(resourceGroupName, l2IsolationDomainName, body, context);
    }

    public Map<String, ArpProperties> getArpEntries() {
        return serviceManager.l2IsolationDomains().getArpEntries(resourceGroupName, l2IsolationDomainName);
    }

    public Map<String, ArpProperties> getArpEntries(Context context) {
        return serviceManager.l2IsolationDomains().getArpEntries(resourceGroupName, l2IsolationDomainName, context);
    }

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

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

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

    public L2IsolationDomainImpl withNetworkFabricId(String networkFabricId) {
        this.innerModel().withNetworkFabricId(networkFabricId);
        return this;
    }

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

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

    public L2IsolationDomainImpl 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;
    }
}
