// 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.HybridIdentityMetadatasClient;
import com.azure.resourcemanager.connectedvmware.fluent.models.HybridIdentityMetadataInner;
import com.azure.resourcemanager.connectedvmware.models.HybridIdentityMetadataList;
import reactor.core.publisher.Mono;

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

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.ConnectedVMwarevSphere/virtualMachines/{virtualMachineName}/hybridIdentityMetadata")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridIdentityMetadataList>> listByVm(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("virtualMachineName") String virtualMachineName,
            @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<HybridIdentityMetadataList>> listByVmNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> createWithResponseAsync(
        String resourceGroupName, String virtualMachineName, String metadataName, HybridIdentityMetadataInner 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName 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,
                            virtualMachineName,
                            metadataName,
                            this.client.getApiVersion(),
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> createWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        String metadataName,
        HybridIdentityMetadataInner 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName 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,
                virtualMachineName,
                metadataName,
                this.client.getApiVersion(),
                body,
                accept,
                context);
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridIdentityMetadataInner> createAsync(
        String resourceGroupName, String virtualMachineName, String metadataName, HybridIdentityMetadataInner body) {
        return createWithResponseAsync(resourceGroupName, virtualMachineName, metadataName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridIdentityMetadataInner> createAsync(
        String resourceGroupName, String virtualMachineName, String metadataName) {
        final HybridIdentityMetadataInner body = null;
        return createWithResponseAsync(resourceGroupName, virtualMachineName, metadataName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HybridIdentityMetadataInner create(
        String resourceGroupName, String virtualMachineName, String metadataName) {
        final HybridIdentityMetadataInner body = null;
        return createAsync(resourceGroupName, virtualMachineName, metadataName, body).block();
    }

    /**
     * Implements HybridIdentityMetadata PUT method.
     *
     * <p>Create Or Update HybridIdentityMetadata.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the hybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HybridIdentityMetadataInner> createWithResponse(
        String resourceGroupName,
        String virtualMachineName,
        String metadataName,
        HybridIdentityMetadataInner body,
        Context context) {
        return createWithResponseAsync(resourceGroupName, virtualMachineName, metadataName, body, context).block();
    }

    /**
     * Gets HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> getWithResponseAsync(
        String resourceGroupName, String virtualMachineName, String metadataName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            metadataName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> getWithResponseAsync(
        String resourceGroupName, String virtualMachineName, String metadataName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName 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,
                virtualMachineName,
                metadataName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Gets HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 HybridIdentityMetadata on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridIdentityMetadataInner> getAsync(
        String resourceGroupName, String virtualMachineName, String metadataName) {
        return getWithResponseAsync(resourceGroupName, virtualMachineName, metadataName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 HybridIdentityMetadata.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HybridIdentityMetadataInner get(String resourceGroupName, String virtualMachineName, String metadataName) {
        return getAsync(resourceGroupName, virtualMachineName, metadataName).block();
    }

    /**
     * Gets HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata GET method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 HybridIdentityMetadata along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HybridIdentityMetadataInner> getWithResponse(
        String resourceGroupName, String virtualMachineName, String metadataName, Context context) {
        return getWithResponseAsync(resourceGroupName, virtualMachineName, metadataName, context).block();
    }

    /**
     * Deletes an HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 virtualMachineName, String metadataName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            metadataName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 virtualMachineName, String metadataName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (metadataName == null) {
            return Mono.error(new IllegalArgumentException("Parameter metadataName 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,
                virtualMachineName,
                metadataName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deletes an HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 virtualMachineName, String metadataName) {
        return deleteWithResponseAsync(resourceGroupName, virtualMachineName, metadataName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes an HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 virtualMachineName, String metadataName) {
        deleteAsync(resourceGroupName, virtualMachineName, metadataName).block();
    }

    /**
     * Deletes an HybridIdentityMetadata.
     *
     * <p>Implements HybridIdentityMetadata DELETE method.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @param metadataName Name of the HybridIdentityMetadata.
     * @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 virtualMachineName, String metadataName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, virtualMachineName, metadataName, context).block();
    }

    /**
     * Implements GET HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridIdentityMetadataInner>> listByVmSinglePageAsync(
        String resourceGroupName, String virtualMachineName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByVm(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<HybridIdentityMetadataInner>>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 HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridIdentityMetadataInner>> listByVmSinglePageAsync(
        String resourceGroupName, String virtualMachineName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByVm(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Implements GET HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<HybridIdentityMetadataInner> listByVmAsync(String resourceGroupName, String virtualMachineName) {
        return new PagedFlux<>(
            () -> listByVmSinglePageAsync(resourceGroupName, virtualMachineName),
            nextLink -> listByVmNextSinglePageAsync(nextLink));
    }

    /**
     * Implements GET HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<HybridIdentityMetadataInner> listByVmAsync(
        String resourceGroupName, String virtualMachineName, Context context) {
        return new PagedFlux<>(
            () -> listByVmSinglePageAsync(resourceGroupName, virtualMachineName, context),
            nextLink -> listByVmNextSinglePageAsync(nextLink, context));
    }

    /**
     * Implements GET HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<HybridIdentityMetadataInner> listByVm(String resourceGroupName, String virtualMachineName) {
        return new PagedIterable<>(listByVmAsync(resourceGroupName, virtualMachineName));
    }

    /**
     * Implements GET HybridIdentityMetadata in a vm.
     *
     * <p>Returns the list of HybridIdentityMetadata of the given vm.
     *
     * @param resourceGroupName The Resource Group Name.
     * @param virtualMachineName Name of the vm.
     * @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 HybridIdentityMetadata as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<HybridIdentityMetadataInner> listByVm(
        String resourceGroupName, String virtualMachineName, Context context) {
        return new PagedIterable<>(listByVmAsync(resourceGroupName, virtualMachineName, 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 HybridIdentityMetadata along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridIdentityMetadataInner>> listByVmNextSinglePageAsync(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.listByVmNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<HybridIdentityMetadataInner>>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 HybridIdentityMetadata along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridIdentityMetadataInner>> listByVmNextSinglePageAsync(
        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
            .listByVmNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
