// 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.NetworkDeviceInner;
import com.azure.resourcemanager.managednetworkfabric.models.GetDeviceStatusProperties;
import com.azure.resourcemanager.managednetworkfabric.models.GetDynamicInterfaceMapsPropertiesItem;
import com.azure.resourcemanager.managednetworkfabric.models.GetStaticInterfaceMapsPropertiesItem;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDevice;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDevicePatchParameters;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDeviceRoleTypes;
import com.azure.resourcemanager.managednetworkfabric.models.ProvisioningState;
import com.azure.resourcemanager.managednetworkfabric.models.SupportPackageProperties;
import com.azure.resourcemanager.managednetworkfabric.models.UpdatePowerCycleProperties;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateVersionProperties;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class NetworkDeviceImpl implements NetworkDevice, NetworkDevice.Definition, NetworkDevice.Update {
    private NetworkDeviceInner 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 version() {
        return this.innerModel().version();
    }

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

    public NetworkDeviceRoleTypes networkDeviceRole() {
        return this.innerModel().networkDeviceRole();
    }

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

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

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

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

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

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

    private String resourceGroupName;

    private String networkDeviceName;

    private NetworkDevicePatchParameters updateBody;

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

    public NetworkDevice create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .create(resourceGroupName, networkDeviceName, this.innerModel(), Context.NONE);
        return this;
    }

    public NetworkDevice create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .create(resourceGroupName, networkDeviceName, this.innerModel(), context);
        return this;
    }

    NetworkDeviceImpl(
        String name, com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = new NetworkDeviceInner();
        this.serviceManager = serviceManager;
        this.networkDeviceName = name;
    }

    public NetworkDeviceImpl update() {
        this.updateBody = new NetworkDevicePatchParameters();
        return this;
    }

    public NetworkDevice apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .update(resourceGroupName, networkDeviceName, updateBody, Context.NONE);
        return this;
    }

    public NetworkDevice apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .update(resourceGroupName, networkDeviceName, updateBody, context);
        return this;
    }

    NetworkDeviceImpl(
        NetworkDeviceInner innerObject,
        com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.networkDeviceName = Utils.getValueFromIdByName(innerObject.id(), "networkDevices");
    }

    public NetworkDevice refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .getByResourceGroupWithResponse(resourceGroupName, networkDeviceName, Context.NONE)
                .getValue();
        return this;
    }

    public NetworkDevice refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getNetworkDevices()
                .getByResourceGroupWithResponse(resourceGroupName, networkDeviceName, context)
                .getValue();
        return this;
    }

    public void reboot() {
        serviceManager.networkDevices().reboot(resourceGroupName, networkDeviceName);
    }

    public void reboot(Context context) {
        serviceManager.networkDevices().reboot(resourceGroupName, networkDeviceName, context);
    }

    public void restoreConfig() {
        serviceManager.networkDevices().restoreConfig(resourceGroupName, networkDeviceName);
    }

    public void restoreConfig(Context context) {
        serviceManager.networkDevices().restoreConfig(resourceGroupName, networkDeviceName, context);
    }

    public void updateVersion(UpdateVersionProperties body) {
        serviceManager.networkDevices().updateVersion(resourceGroupName, networkDeviceName, body);
    }

    public void updateVersion(UpdateVersionProperties body, Context context) {
        serviceManager.networkDevices().updateVersion(resourceGroupName, networkDeviceName, body, context);
    }

    public SupportPackageProperties generateSupportPackage() {
        return serviceManager.networkDevices().generateSupportPackage(resourceGroupName, networkDeviceName);
    }

    public SupportPackageProperties generateSupportPackage(Context context) {
        return serviceManager.networkDevices().generateSupportPackage(resourceGroupName, networkDeviceName, context);
    }

    public void updatePowerCycle(UpdatePowerCycleProperties body) {
        serviceManager.networkDevices().updatePowerCycle(resourceGroupName, networkDeviceName, body);
    }

    public void updatePowerCycle(UpdatePowerCycleProperties body, Context context) {
        serviceManager.networkDevices().updatePowerCycle(resourceGroupName, networkDeviceName, body, context);
    }

    public GetDeviceStatusProperties getStatus() {
        return serviceManager.networkDevices().getStatus(resourceGroupName, networkDeviceName);
    }

    public GetDeviceStatusProperties getStatus(Context context) {
        return serviceManager.networkDevices().getStatus(resourceGroupName, networkDeviceName, context);
    }

    public List<GetStaticInterfaceMapsPropertiesItem> getStaticInterfaceMaps() {
        return serviceManager.networkDevices().getStaticInterfaceMaps(resourceGroupName, networkDeviceName);
    }

    public List<GetStaticInterfaceMapsPropertiesItem> getStaticInterfaceMaps(Context context) {
        return serviceManager.networkDevices().getStaticInterfaceMaps(resourceGroupName, networkDeviceName, context);
    }

    public List<GetDynamicInterfaceMapsPropertiesItem> getDynamicInterfaceMaps() {
        return serviceManager.networkDevices().getDynamicInterfaceMaps(resourceGroupName, networkDeviceName);
    }

    public List<GetDynamicInterfaceMapsPropertiesItem> getDynamicInterfaceMaps(Context context) {
        return serviceManager.networkDevices().getDynamicInterfaceMaps(resourceGroupName, networkDeviceName, context);
    }

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

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

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

    public NetworkDeviceImpl withNetworkDeviceSku(String networkDeviceSku) {
        this.innerModel().withNetworkDeviceSku(networkDeviceSku);
        return this;
    }

    public NetworkDeviceImpl withNetworkDeviceRole(NetworkDeviceRoleTypes networkDeviceRole) {
        this.innerModel().withNetworkDeviceRole(networkDeviceRole);
        return this;
    }

    public NetworkDeviceImpl withHostname(String hostname) {
        if (isInCreateMode()) {
            this.innerModel().withHostname(hostname);
            return this;
        } else {
            this.updateBody.withHostname(hostname);
            return this;
        }
    }

    public NetworkDeviceImpl withSerialNumber(String serialNumber) {
        if (isInCreateMode()) {
            this.innerModel().withSerialNumber(serialNumber);
            return this;
        } else {
            this.updateBody.withSerialNumber(serialNumber);
            return this;
        }
    }

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