// 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.L3IsolationDomainInner;
import com.azure.resourcemanager.managednetworkfabric.models.AggregateRouteConfiguration;
import com.azure.resourcemanager.managednetworkfabric.models.EnableDisableOnResources;
import com.azure.resourcemanager.managednetworkfabric.models.EnabledDisabledState;
import com.azure.resourcemanager.managednetworkfabric.models.L3IsolationDomain;
import com.azure.resourcemanager.managednetworkfabric.models.L3IsolationDomainPatch;
import com.azure.resourcemanager.managednetworkfabric.models.L3IsolationDomainPatchPropertiesConnectedSubnetRoutePolicy;
import com.azure.resourcemanager.managednetworkfabric.models.ProvisioningState;
import com.azure.resourcemanager.managednetworkfabric.models.RedistributeConnectedSubnets;
import com.azure.resourcemanager.managednetworkfabric.models.RedistributeStaticRoutes;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateAdministrativeState;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class L3IsolationDomainImpl
    implements L3IsolationDomain, L3IsolationDomain.Definition, L3IsolationDomain.Update {
    private L3IsolationDomainInner 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 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> optionBDisabledOnResources() {
        List<String> inner = this.innerModel().optionBDisabledOnResources();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

    public RedistributeConnectedSubnets redistributeConnectedSubnets() {
        return this.innerModel().redistributeConnectedSubnets();
    }

    public RedistributeStaticRoutes redistributeStaticRoutes() {
        return this.innerModel().redistributeStaticRoutes();
    }

    public AggregateRouteConfiguration aggregateRouteConfiguration() {
        return this.innerModel().aggregateRouteConfiguration();
    }

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

    public L3IsolationDomainPatchPropertiesConnectedSubnetRoutePolicy connectedSubnetRoutePolicy() {
        return this.innerModel().connectedSubnetRoutePolicy();
    }

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

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

    private String resourceGroupName;

    private String l3IsolationDomainName;

    private L3IsolationDomainPatch updateBody;

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

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

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

    L3IsolationDomainImpl(
        String name, com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = new L3IsolationDomainInner();
        this.serviceManager = serviceManager;
        this.l3IsolationDomainName = name;
    }

    public L3IsolationDomainImpl update() {
        this.updateBody = new L3IsolationDomainPatch();
        return this;
    }

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

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

    L3IsolationDomainImpl(
        L3IsolationDomainInner 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");
    }

    public L3IsolationDomain refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3IsolationDomains()
                .getByResourceGroupWithResponse(resourceGroupName, l3IsolationDomainName, Context.NONE)
                .getValue();
        return this;
    }

    public L3IsolationDomain refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getL3IsolationDomains()
                .getByResourceGroupWithResponse(resourceGroupName, l3IsolationDomainName, context)
                .getValue();
        return this;
    }

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

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

    public void updateOptionBAdministrativeState(UpdateAdministrativeState body) {
        serviceManager
            .l3IsolationDomains()
            .updateOptionBAdministrativeState(resourceGroupName, l3IsolationDomainName, body);
    }

    public void updateOptionBAdministrativeState(UpdateAdministrativeState body, Context context) {
        serviceManager
            .l3IsolationDomains()
            .updateOptionBAdministrativeState(resourceGroupName, l3IsolationDomainName, body, context);
    }

    public void clearArpTable(EnableDisableOnResources body) {
        serviceManager.l3IsolationDomains().clearArpTable(resourceGroupName, l3IsolationDomainName, body);
    }

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

    public void clearNeighborTable(EnableDisableOnResources body) {
        serviceManager.l3IsolationDomains().clearNeighborTable(resourceGroupName, l3IsolationDomainName, body);
    }

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

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

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

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

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

    public L3IsolationDomainImpl withRedistributeConnectedSubnets(
        RedistributeConnectedSubnets redistributeConnectedSubnets) {
        if (isInCreateMode()) {
            this.innerModel().withRedistributeConnectedSubnets(redistributeConnectedSubnets);
            return this;
        } else {
            this.updateBody.withRedistributeConnectedSubnets(redistributeConnectedSubnets);
            return this;
        }
    }

    public L3IsolationDomainImpl withRedistributeStaticRoutes(RedistributeStaticRoutes redistributeStaticRoutes) {
        if (isInCreateMode()) {
            this.innerModel().withRedistributeStaticRoutes(redistributeStaticRoutes);
            return this;
        } else {
            this.updateBody.withRedistributeStaticRoutes(redistributeStaticRoutes);
            return this;
        }
    }

    public L3IsolationDomainImpl withAggregateRouteConfiguration(
        AggregateRouteConfiguration aggregateRouteConfiguration) {
        if (isInCreateMode()) {
            this.innerModel().withAggregateRouteConfiguration(aggregateRouteConfiguration);
            return this;
        } else {
            this.updateBody.withAggregateRouteConfiguration(aggregateRouteConfiguration);
            return this;
        }
    }

    public L3IsolationDomainImpl withDescription(String description) {
        if (isInCreateMode()) {
            this.innerModel().withDescription(description);
            return this;
        } else {
            this.updateBody.withDescription(description);
            return this;
        }
    }

    public L3IsolationDomainImpl withConnectedSubnetRoutePolicy(
        L3IsolationDomainPatchPropertiesConnectedSubnetRoutePolicy connectedSubnetRoutePolicy) {
        if (isInCreateMode()) {
            this.innerModel().withConnectedSubnetRoutePolicy(connectedSubnetRoutePolicy);
            return this;
        } else {
            this.updateBody.withConnectedSubnetRoutePolicy(connectedSubnetRoutePolicy);
            return this;
        }
    }

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

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