// 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.TrunkedNetworkInner;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.HybridAksPluginType;
import com.azure.resourcemanager.networkcloud.models.TrunkedNetwork;
import com.azure.resourcemanager.networkcloud.models.TrunkedNetworkDetailedStatus;
import com.azure.resourcemanager.networkcloud.models.TrunkedNetworkPatchParameters;
import com.azure.resourcemanager.networkcloud.models.TrunkedNetworkProvisioningState;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class TrunkedNetworkImpl implements TrunkedNetwork, TrunkedNetwork.Definition, TrunkedNetwork.Update {
    private TrunkedNetworkInner 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 TrunkedNetworkDetailedStatus 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 HybridAksPluginType hybridAksPluginType() {
        return this.innerModel().hybridAksPluginType();
    }

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

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

    public TrunkedNetworkProvisioningState 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 List<Long> vlans() {
        List<Long> inner = this.innerModel().vlans();
        if (inner != null) {
            return Collections.unmodifiableList(inner);
        } else {
            return Collections.emptyList();
        }
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

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

    private String resourceGroupName;

    private String trunkedNetworkName;

    private TrunkedNetworkPatchParameters updateTrunkedNetworkUpdateParameters;

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

    public TrunkedNetwork create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .createOrUpdate(resourceGroupName, trunkedNetworkName, this.innerModel(), Context.NONE);
        return this;
    }

    public TrunkedNetwork create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .createOrUpdate(resourceGroupName, trunkedNetworkName, this.innerModel(), context);
        return this;
    }

    TrunkedNetworkImpl(String name, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = new TrunkedNetworkInner();
        this.serviceManager = serviceManager;
        this.trunkedNetworkName = name;
    }

    public TrunkedNetworkImpl update() {
        this.updateTrunkedNetworkUpdateParameters = new TrunkedNetworkPatchParameters();
        return this;
    }

    public TrunkedNetwork apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .updateWithResponse(
                    resourceGroupName, trunkedNetworkName, updateTrunkedNetworkUpdateParameters, Context.NONE)
                .getValue();
        return this;
    }

    public TrunkedNetwork apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .updateWithResponse(
                    resourceGroupName, trunkedNetworkName, updateTrunkedNetworkUpdateParameters, context)
                .getValue();
        return this;
    }

    TrunkedNetworkImpl(
        TrunkedNetworkInner innerObject, com.azure.resourcemanager.networkcloud.NetworkCloudManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.trunkedNetworkName = Utils.getValueFromIdByName(innerObject.id(), "trunkedNetworks");
    }

    public TrunkedNetwork refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .getByResourceGroupWithResponse(resourceGroupName, trunkedNetworkName, Context.NONE)
                .getValue();
        return this;
    }

    public TrunkedNetwork refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getTrunkedNetworks()
                .getByResourceGroupWithResponse(resourceGroupName, trunkedNetworkName, context)
                .getValue();
        return this;
    }

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

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

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

    public TrunkedNetworkImpl withIsolationDomainIds(List<String> isolationDomainIds) {
        this.innerModel().withIsolationDomainIds(isolationDomainIds);
        return this;
    }

    public TrunkedNetworkImpl withVlans(List<Long> vlans) {
        this.innerModel().withVlans(vlans);
        return this;
    }

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

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

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

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