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

package com.azure.resourcemanager.connectedvmware.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.connectedvmware.fluent.InventoryItemsClient;
import com.azure.resourcemanager.connectedvmware.fluent.models.InventoryItemInner;
import com.azure.resourcemanager.connectedvmware.models.InventoryItemsList;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in InventoryItemsClient. */
public final class InventoryItemsClientImpl implements InventoryItemsClient {
    /** The proxy service used to perform REST calls. */
    private final InventoryItemsService service;

    /** The service client containing this operation class. */
    private final ConnectedVMwareClientImpl client;

    /**
     * Initializes an instance of InventoryItemsClientImpl.
     *
     * @param client the instance of the service client containing this operation class.
     */
    InventoryItemsClientImpl(ConnectedVMwareClientImpl client) {
        this.service =
            RestProxy.create(InventoryItemsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for ConnectedVMwareClientInventoryItems to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "ConnectedVMwareClien")
    private interface InventoryItemsService {
        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.ConnectedVMwarevSphere/vcenters/{vcenterName}/inventoryItems/{inventoryItemName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InventoryItemInner>> create(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("vcenterName") String vcenterName,
            @PathParam("inventoryItemName") String inventoryItemName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") InventoryItemInner body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.ConnectedVMwarevSphere/vcenters/{vcenterName}/inventoryItems/{inventoryItemName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InventoryItemInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("vcenterName") String vcenterName,
            @PathParam("inventoryItemName") String inventoryItemName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.ConnectedVMwarevSphere/vcenters/{vcenterName}/inventoryItems/{inventoryItemName}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("vcenterName") String vcenterName,
            @PathParam("inventoryItemName") String inventoryItemName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.ConnectedVMwarevSphere/vcenters/{vcenterName}/inventoryItems")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InventoryItemsList>> listByVCenter(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("vcenterName") String vcenterName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InventoryItemsList>> listByVCenterNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param body Request payload.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InventoryItemInner>> createWithResponseAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName, InventoryItemInner body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        if (body != null) {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            vcenterName,
                            inventoryItemName,
                            this.client.getApiVersion(),
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param body Request payload.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InventoryItemInner>> createWithResponseAsync(
        String resourceGroupName,
        String vcenterName,
        String inventoryItemName,
        InventoryItemInner body,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        if (body != null) {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                vcenterName,
                inventoryItemName,
                this.client.getApiVersion(),
                body,
                accept,
                context);
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param body Request payload.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InventoryItemInner> createAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName, InventoryItemInner body) {
        return createWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InventoryItemInner> createAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName) {
        final InventoryItemInner body = null;
        return createWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public InventoryItemInner create(String resourceGroupName, String vcenterName, String inventoryItemName) {
        final InventoryItemInner body = null;
        return createAsync(resourceGroupName, vcenterName, inventoryItemName, body).block();
    }

    /**
     * Implements InventoryItem PUT method.
     *
     * <p>Create Or Update InventoryItem.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param body Request payload.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<InventoryItemInner> createWithResponse(
        String resourceGroupName,
        String vcenterName,
        String inventoryItemName,
        InventoryItemInner body,
        Context context) {
        return createWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName, body, context).block();
    }

    /**
     * Gets InventoryItem.
     *
     * <p>Implements InventoryItem GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InventoryItemInner>> getWithResponseAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            vcenterName,
                            inventoryItemName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets InventoryItem.
     *
     * <p>Implements InventoryItem GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InventoryItemInner>> getWithResponseAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                vcenterName,
                inventoryItemName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Gets InventoryItem.
     *
     * <p>Implements InventoryItem GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InventoryItemInner> getAsync(String resourceGroupName, String vcenterName, String inventoryItemName) {
        return getWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets InventoryItem.
     *
     * <p>Implements InventoryItem GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public InventoryItemInner get(String resourceGroupName, String vcenterName, String inventoryItemName) {
        return getAsync(resourceGroupName, vcenterName, inventoryItemName).block();
    }

    /**
     * Gets InventoryItem.
     *
     * <p>Implements InventoryItem GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return defines the inventory item along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<InventoryItemInner> getWithResponse(
        String resourceGroupName, String vcenterName, String inventoryItemName, Context context) {
        return getWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName, context).block();
    }

    /**
     * Deletes an inventoryItem.
     *
     * <p>Implements inventoryItem DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            vcenterName,
                            inventoryItemName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an inventoryItem.
     *
     * <p>Implements inventoryItem DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String vcenterName, String inventoryItemName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        if (inventoryItemName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter inventoryItemName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                vcenterName,
                inventoryItemName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deletes an inventoryItem.
     *
     * <p>Implements inventoryItem DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String vcenterName, String inventoryItemName) {
        return deleteWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes an inventoryItem.
     *
     * <p>Implements inventoryItem DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String vcenterName, String inventoryItemName) {
        deleteAsync(resourceGroupName, vcenterName, inventoryItemName).block();
    }

    /**
     * Deletes an inventoryItem.
     *
     * <p>Implements inventoryItem DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param inventoryItemName Name of the inventoryItem.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String resourceGroupName, String vcenterName, String inventoryItemName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, vcenterName, inventoryItemName, context).block();
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InventoryItemInner>> listByVCenterSinglePageAsync(
        String resourceGroupName, String vcenterName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByVCenter(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            vcenterName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<InventoryItemInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InventoryItemInner>> listByVCenterSinglePageAsync(
        String resourceGroupName, String vcenterName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (vcenterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vcenterName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByVCenter(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                vcenterName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InventoryItemInner> listByVCenterAsync(String resourceGroupName, String vcenterName) {
        return new PagedFlux<>(
            () -> listByVCenterSinglePageAsync(resourceGroupName, vcenterName),
            nextLink -> listByVCenterNextSinglePageAsync(nextLink));
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InventoryItemInner> listByVCenterAsync(
        String resourceGroupName, String vcenterName, Context context) {
        return new PagedFlux<>(
            () -> listByVCenterSinglePageAsync(resourceGroupName, vcenterName, context),
            nextLink -> listByVCenterNextSinglePageAsync(nextLink, context));
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InventoryItemInner> listByVCenter(String resourceGroupName, String vcenterName) {
        return new PagedIterable<>(listByVCenterAsync(resourceGroupName, vcenterName));
    }

    /**
     * Implements GET inventoryItems in a vCenter.
     *
     * <p>Returns the list of inventoryItems of the given vCenter.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param vcenterName Name of the vCenter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InventoryItemInner> listByVCenter(
        String resourceGroupName, String vcenterName, Context context) {
        return new PagedIterable<>(listByVCenterAsync(resourceGroupName, vcenterName, context));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InventoryItemInner>> listByVCenterNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listByVCenterNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<InventoryItemInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of InventoryItems along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InventoryItemInner>> listByVCenterNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByVCenterNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
