// 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.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.managednetworkfabric.fluent.NetworkFabricControllersClient;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.NetworkFabricControllerInner;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkFabricController;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkFabricControllers;

public final class NetworkFabricControllersImpl implements NetworkFabricControllers {
    private static final ClientLogger LOGGER = new ClientLogger(NetworkFabricControllersImpl.class);

    private final NetworkFabricControllersClient innerClient;

    private final com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager;

    public NetworkFabricControllersImpl(
        NetworkFabricControllersClient innerClient,
        com.azure.resourcemanager.managednetworkfabric.ManagedNetworkFabricManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<NetworkFabricController> getByResourceGroupWithResponse(
        String resourceGroupName, String networkFabricControllerName, Context context) {
        Response<NetworkFabricControllerInner> inner =
            this
                .serviceClient()
                .getByResourceGroupWithResponse(resourceGroupName, networkFabricControllerName, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new NetworkFabricControllerImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public NetworkFabricController getByResourceGroup(String resourceGroupName, String networkFabricControllerName) {
        NetworkFabricControllerInner inner =
            this.serviceClient().getByResourceGroup(resourceGroupName, networkFabricControllerName);
        if (inner != null) {
            return new NetworkFabricControllerImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public void deleteByResourceGroup(String resourceGroupName, String networkFabricControllerName) {
        this.serviceClient().delete(resourceGroupName, networkFabricControllerName);
    }

    public void delete(String resourceGroupName, String networkFabricControllerName, Context context) {
        this.serviceClient().delete(resourceGroupName, networkFabricControllerName, context);
    }

    public PagedIterable<NetworkFabricController> listByResourceGroup(String resourceGroupName) {
        PagedIterable<NetworkFabricControllerInner> inner = this.serviceClient().listByResourceGroup(resourceGroupName);
        return Utils.mapPage(inner, inner1 -> new NetworkFabricControllerImpl(inner1, this.manager()));
    }

    public PagedIterable<NetworkFabricController> listByResourceGroup(String resourceGroupName, Context context) {
        PagedIterable<NetworkFabricControllerInner> inner =
            this.serviceClient().listByResourceGroup(resourceGroupName, context);
        return Utils.mapPage(inner, inner1 -> new NetworkFabricControllerImpl(inner1, this.manager()));
    }

    public PagedIterable<NetworkFabricController> list() {
        PagedIterable<NetworkFabricControllerInner> inner = this.serviceClient().list();
        return Utils.mapPage(inner, inner1 -> new NetworkFabricControllerImpl(inner1, this.manager()));
    }

    public PagedIterable<NetworkFabricController> list(Context context) {
        PagedIterable<NetworkFabricControllerInner> inner = this.serviceClient().list(context);
        return Utils.mapPage(inner, inner1 -> new NetworkFabricControllerImpl(inner1, this.manager()));
    }

    public void enableWorkloadManagementNetwork(String resourceGroupName, String networkFabricControllerName) {
        this.serviceClient().enableWorkloadManagementNetwork(resourceGroupName, networkFabricControllerName);
    }

    public void enableWorkloadManagementNetwork(
        String resourceGroupName, String networkFabricControllerName, Context context) {
        this.serviceClient().enableWorkloadManagementNetwork(resourceGroupName, networkFabricControllerName, context);
    }

    public void disableWorkloadManagementNetwork(String resourceGroupName, String networkFabricControllerName) {
        this.serviceClient().disableWorkloadManagementNetwork(resourceGroupName, networkFabricControllerName);
    }

    public void disableWorkloadManagementNetwork(
        String resourceGroupName, String networkFabricControllerName, Context context) {
        this.serviceClient().disableWorkloadManagementNetwork(resourceGroupName, networkFabricControllerName, context);
    }

    public NetworkFabricController getById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String networkFabricControllerName = Utils.getValueFromIdByName(id, "networkFabricControllers");
        if (networkFabricControllerName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFabricControllers'.",
                                id)));
        }
        return this
            .getByResourceGroupWithResponse(resourceGroupName, networkFabricControllerName, Context.NONE)
            .getValue();
    }

    public Response<NetworkFabricController> getByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String networkFabricControllerName = Utils.getValueFromIdByName(id, "networkFabricControllers");
        if (networkFabricControllerName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFabricControllers'.",
                                id)));
        }
        return this.getByResourceGroupWithResponse(resourceGroupName, networkFabricControllerName, context);
    }

    public void deleteById(String id) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String networkFabricControllerName = Utils.getValueFromIdByName(id, "networkFabricControllers");
        if (networkFabricControllerName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFabricControllers'.",
                                id)));
        }
        this.delete(resourceGroupName, networkFabricControllerName, Context.NONE);
    }

    public void deleteByIdWithResponse(String id, Context context) {
        String resourceGroupName = Utils.getValueFromIdByName(id, "resourceGroups");
        if (resourceGroupName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id)));
        }
        String networkFabricControllerName = Utils.getValueFromIdByName(id, "networkFabricControllers");
        if (networkFabricControllerName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFabricControllers'.",
                                id)));
        }
        this.delete(resourceGroupName, networkFabricControllerName, context);
    }

    private NetworkFabricControllersClient serviceClient() {
        return this.innerClient;
    }

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

    public NetworkFabricControllerImpl define(String name) {
        return new NetworkFabricControllerImpl(name, this.manager());
    }
}
