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

package com.azure.resourcemanager.hybridcontainerservice.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.hybridcontainerservice.fluent.HybridIdentityMetadatasClient;
import com.azure.resourcemanager.hybridcontainerservice.fluent.models.HybridIdentityMetadataInner;
import com.azure.resourcemanager.hybridcontainerservice.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 HybridContainerServiceImpl client;

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

    /**
     * The interface defining all the services for HybridContainerServiceHybridIdentityMetadatas to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HybridContainerServi")
    public interface HybridIdentityMetadatasService {
        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.HybridContainerService/provisionedClusters/{resourceName}/hybridIdentityMetadata"
                + "/{hybridIdentityMetadataResourceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridIdentityMetadataInner>> put(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceName") String resourceName,
            @PathParam("hybridIdentityMetadataResourceName") String hybridIdentityMetadataResourceName,
            @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.HybridContainerService/provisionedClusters/{resourceName}/hybridIdentityMetadata"
                + "/{hybridIdentityMetadataResourceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridIdentityMetadataInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceName") String resourceName,
            @PathParam("hybridIdentityMetadataResourceName") String hybridIdentityMetadataResourceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Creates the hybrid identity metadata resource
     *
     * <p>Creates the hybrid identity metadata proxy resource that facilitates the managed identity provisioning.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @param body Defines 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>> putWithResponseAsync(
        String resourceGroupName,
        String resourceName,
        String hybridIdentityMetadataResourceName,
        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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .put(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            resourceName,
                            hybridIdentityMetadataResourceName,
                            this.client.getApiVersion(),
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates the hybrid identity metadata resource
     *
     * <p>Creates the hybrid identity metadata proxy resource that facilitates the managed identity provisioning.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @param body Defines 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>> putWithResponseAsync(
        String resourceGroupName,
        String resourceName,
        String hybridIdentityMetadataResourceName,
        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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .put(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                resourceName,
                hybridIdentityMetadataResourceName,
                this.client.getApiVersion(),
                body,
                accept,
                context);
    }

    /**
     * Creates the hybrid identity metadata resource
     *
     * <p>Creates the hybrid identity metadata proxy resource that facilitates the managed identity provisioning.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @param body Defines 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> putAsync(
        String resourceGroupName,
        String resourceName,
        String hybridIdentityMetadataResourceName,
        HybridIdentityMetadataInner body) {
        return putWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates the hybrid identity metadata resource
     *
     * <p>Creates the hybrid identity metadata proxy resource that facilitates the managed identity provisioning.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @param body Defines 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> putWithResponse(
        String resourceGroupName,
        String resourceName,
        String hybridIdentityMetadataResourceName,
        HybridIdentityMetadataInner body,
        Context context) {
        return putWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, body, context)
            .block();
    }

    /**
     * Creates the hybrid identity metadata resource
     *
     * <p>Creates the hybrid identity metadata proxy resource that facilitates the managed identity provisioning.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @param body Defines 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 put(
        String resourceGroupName,
        String resourceName,
        String hybridIdentityMetadataResourceName,
        HybridIdentityMetadataInner body) {
        return putWithResponse(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, body, Context.NONE)
            .getValue();
    }

    /**
     * Get the hybrid identity metadata resource
     *
     * <p>Get the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 hybrid identity metadata proxy resource along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> getWithResponseAsync(
        String resourceGroupName, String resourceName, String hybridIdentityMetadataResourceName) {
        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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            resourceName,
                            hybridIdentityMetadataResourceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the hybrid identity metadata resource
     *
     * <p>Get the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 hybrid identity metadata proxy resource along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridIdentityMetadataInner>> getWithResponseAsync(
        String resourceGroupName, String resourceName, String hybridIdentityMetadataResourceName, 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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName 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,
                resourceName,
                hybridIdentityMetadataResourceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Get the hybrid identity metadata resource
     *
     * <p>Get the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 hybrid identity metadata proxy resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridIdentityMetadataInner> getAsync(
        String resourceGroupName, String resourceName, String hybridIdentityMetadataResourceName) {
        return getWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the hybrid identity metadata resource
     *
     * <p>Get the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 hybrid identity metadata proxy resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HybridIdentityMetadataInner> getWithResponse(
        String resourceGroupName, String resourceName, String hybridIdentityMetadataResourceName, Context context) {
        return getWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, context)
            .block();
    }

    /**
     * Get the hybrid identity metadata resource
     *
     * <p>Get the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 hybrid identity metadata proxy resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HybridIdentityMetadataInner get(
        String resourceGroupName, String resourceName, String hybridIdentityMetadataResourceName) {
        return getWithResponse(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, Context.NONE)
            .getValue();
    }

    /**
     * Deletes the hybrid identity metadata resource
     *
     * <p>Deletes the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 resourceName, String hybridIdentityMetadataResourceName) {
        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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            resourceName,
                            hybridIdentityMetadataResourceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the hybrid identity metadata resource
     *
     * <p>Deletes the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 resourceName, String hybridIdentityMetadataResourceName, 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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (hybridIdentityMetadataResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridIdentityMetadataResourceName 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,
                resourceName,
                hybridIdentityMetadataResourceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deletes the hybrid identity metadata resource
     *
     * <p>Deletes the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 resourceName, String hybridIdentityMetadataResourceName) {
        return deleteWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes the hybrid identity metadata resource
     *
     * <p>Deletes the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 resourceName, String hybridIdentityMetadataResourceName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, context)
            .block();
    }

    /**
     * Deletes the hybrid identity metadata resource
     *
     * <p>Deletes the hybrid identity metadata proxy resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @param hybridIdentityMetadataResourceName Parameter for the name of the hybrid identity metadata resource.
     * @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 resourceName, String hybridIdentityMetadataResourceName) {
        deleteWithResponse(resourceGroupName, resourceName, hybridIdentityMetadataResourceName, Context.NONE);
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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>> listByClusterSinglePageAsync(
        String resourceGroupName, String resourceName) {
        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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByCluster(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            resourceName,
                            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()));
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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>> listByClusterSinglePageAsync(
        String resourceGroupName, String resourceName, 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 (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByCluster(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                resourceName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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> listByClusterAsync(String resourceGroupName, String resourceName) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, resourceName),
            nextLink -> listByClusterNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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> listByClusterAsync(
        String resourceGroupName, String resourceName, Context context) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, resourceName, context),
            nextLink -> listByClusterNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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> listByCluster(String resourceGroupName, String resourceName) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, resourceName));
    }

    /**
     * Lists the hybrid identity metadata resources in a cluster
     *
     * <p>Lists the hybrid identity metadata proxy resource in a cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceName Parameter for the name of the provisioned cluster.
     * @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> listByCluster(
        String resourceGroupName, String resourceName, Context context) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, resourceName, context));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>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>> listByClusterNextSinglePageAsync(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.listByClusterNext(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 URL to get the next list of items
     *     <p>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>> listByClusterNextSinglePageAsync(
        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
            .listByClusterNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
