// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.hybridnetwork.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.hybridnetwork.fluent.VendorNetworkFunctionsClient;
import com.azure.resourcemanager.hybridnetwork.fluent.models.VendorNetworkFunctionInner;
import com.azure.resourcemanager.hybridnetwork.models.VendorNetworkFunction;
import com.azure.resourcemanager.hybridnetwork.models.VendorNetworkFunctions;

public final class VendorNetworkFunctionsImpl implements VendorNetworkFunctions {
    private static final ClientLogger LOGGER = new ClientLogger(VendorNetworkFunctionsImpl.class);

    private final VendorNetworkFunctionsClient innerClient;

    private final com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager;

    public VendorNetworkFunctionsImpl(
        VendorNetworkFunctionsClient innerClient,
        com.azure.resourcemanager.hybridnetwork.HybridNetworkManager serviceManager) {
        this.innerClient = innerClient;
        this.serviceManager = serviceManager;
    }

    public Response<VendorNetworkFunction> getWithResponse(
        String locationName, String vendorName, String serviceKey, Context context) {
        Response<VendorNetworkFunctionInner> inner =
            this.serviceClient().getWithResponse(locationName, vendorName, serviceKey, context);
        if (inner != null) {
            return new SimpleResponse<>(
                inner.getRequest(),
                inner.getStatusCode(),
                inner.getHeaders(),
                new VendorNetworkFunctionImpl(inner.getValue(), this.manager()));
        } else {
            return null;
        }
    }

    public VendorNetworkFunction get(String locationName, String vendorName, String serviceKey) {
        VendorNetworkFunctionInner inner = this.serviceClient().get(locationName, vendorName, serviceKey);
        if (inner != null) {
            return new VendorNetworkFunctionImpl(inner, this.manager());
        } else {
            return null;
        }
    }

    public PagedIterable<VendorNetworkFunction> list(String locationName, String vendorName) {
        PagedIterable<VendorNetworkFunctionInner> inner = this.serviceClient().list(locationName, vendorName);
        return Utils.mapPage(inner, inner1 -> new VendorNetworkFunctionImpl(inner1, this.manager()));
    }

    public PagedIterable<VendorNetworkFunction> list(
        String locationName, String vendorName, String filter, Context context) {
        PagedIterable<VendorNetworkFunctionInner> inner =
            this.serviceClient().list(locationName, vendorName, filter, context);
        return Utils.mapPage(inner, inner1 -> new VendorNetworkFunctionImpl(inner1, this.manager()));
    }

    public VendorNetworkFunction getById(String id) {
        String locationName = Utils.getValueFromIdByName(id, "locations");
        if (locationName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id)));
        }
        String vendorName = Utils.getValueFromIdByName(id, "vendors");
        if (vendorName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendors'.", id)));
        }
        String serviceKey = Utils.getValueFromIdByName(id, "networkFunctions");
        if (serviceKey == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFunctions'.", id)));
        }
        return this.getWithResponse(locationName, vendorName, serviceKey, Context.NONE).getValue();
    }

    public Response<VendorNetworkFunction> getByIdWithResponse(String id, Context context) {
        String locationName = Utils.getValueFromIdByName(id, "locations");
        if (locationName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id)));
        }
        String vendorName = Utils.getValueFromIdByName(id, "vendors");
        if (vendorName == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String.format("The resource ID '%s' is not valid. Missing path segment 'vendors'.", id)));
        }
        String serviceKey = Utils.getValueFromIdByName(id, "networkFunctions");
        if (serviceKey == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        String
                            .format(
                                "The resource ID '%s' is not valid. Missing path segment 'networkFunctions'.", id)));
        }
        return this.getWithResponse(locationName, vendorName, serviceKey, context);
    }

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

    private com.azure.resourcemanager.hybridnetwork.HybridNetworkManager manager() {
        return this.serviceManager;
    }

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