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

package com.azure.resourcemanager.storagecache.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.Post;
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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.storagecache.fluent.StorageTargetsClient;
import com.azure.resourcemanager.storagecache.fluent.models.StorageTargetInner;
import com.azure.resourcemanager.storagecache.models.StorageTargetsResult;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for StorageCacheManagementClientStorageTargets to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "StorageCacheManageme")
    public interface StorageTargetsService {
        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}/dnsRefresh")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> dnsRefresh(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @PathParam("storageTargetName") String storageTargetName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<StorageTargetsResult>> listByCache(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @PathParam("storageTargetName") String storageTargetName,
            @QueryParam("force") String force,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<StorageTargetInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @PathParam("storageTargetName") String storageTargetName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}")
        @ExpectedResponses({200, 201, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @PathParam("storageTargetName") String storageTargetName,
            @BodyParam("application/json") StorageTargetInner storagetarget,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}/restoreDefaults")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> restoreDefaults(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("cacheName") String cacheName,
            @PathParam("storageTargetName") String storageTargetName,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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<Flux<ByteBuffer>>> dnsRefreshWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .dnsRefresh(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            storageTargetName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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<Flux<ByteBuffer>>> dnsRefreshWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .dnsRefresh(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                storageTargetName,
                accept,
                context);
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDnsRefreshAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            dnsRefreshWithResponseAsync(resourceGroupName, cacheName, storageTargetName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDnsRefreshAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            dnsRefreshWithResponseAsync(resourceGroupName, cacheName, storageTargetName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDnsRefresh(
        String resourceGroupName, String cacheName, String storageTargetName) {
        return this.beginDnsRefreshAsync(resourceGroupName, cacheName, storageTargetName).getSyncPoller();
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDnsRefresh(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        return this.beginDnsRefreshAsync(resourceGroupName, cacheName, storageTargetName, context).getSyncPoller();
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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> dnsRefreshAsync(String resourceGroupName, String cacheName, String storageTargetName) {
        return beginDnsRefreshAsync(resourceGroupName, cacheName, storageTargetName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> dnsRefreshAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        return beginDnsRefreshAsync(resourceGroupName, cacheName, storageTargetName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 dnsRefresh(String resourceGroupName, String cacheName, String storageTargetName) {
        dnsRefreshAsync(resourceGroupName, cacheName, storageTargetName).block();
    }

    /**
     * Tells a storage target to refresh its DNS information.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void dnsRefresh(String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        dnsRefreshAsync(resourceGroupName, cacheName, storageTargetName, context).block();
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 list of Storage Targets along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<StorageTargetInner>> listByCacheSinglePageAsync(
        String resourceGroupName, String cacheName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByCache(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            accept,
                            context))
            .<PagedResponse<StorageTargetInner>>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()));
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 a list of Storage Targets along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<StorageTargetInner>> listByCacheSinglePageAsync(
        String resourceGroupName, String cacheName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByCache(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 list of Storage Targets as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<StorageTargetInner> listByCacheAsync(String resourceGroupName, String cacheName) {
        return new PagedFlux<>(
            () -> listByCacheSinglePageAsync(resourceGroupName, cacheName),
            nextLink -> listByCacheNextSinglePageAsync(nextLink));
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 a list of Storage Targets as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<StorageTargetInner> listByCacheAsync(
        String resourceGroupName, String cacheName, Context context) {
        return new PagedFlux<>(
            () -> listByCacheSinglePageAsync(resourceGroupName, cacheName, context),
            nextLink -> listByCacheNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 list of Storage Targets as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<StorageTargetInner> listByCache(String resourceGroupName, String cacheName) {
        return new PagedIterable<>(listByCacheAsync(resourceGroupName, cacheName));
    }

    /**
     * Returns a list of Storage Targets for the specified cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @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 a list of Storage Targets as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<StorageTargetInner> listByCache(String resourceGroupName, String cacheName, Context context) {
        return new PagedIterable<>(listByCacheAsync(resourceGroupName, cacheName, context));
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, String force) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            storageTargetName,
                            force,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, String force, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                storageTargetName,
                force,
                accept,
                context);
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String cacheName, String storageTargetName, String force) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, cacheName, storageTargetName, force);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        final String force = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, cacheName, storageTargetName, force);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String cacheName, String storageTargetName, String force, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, cacheName, storageTargetName, force, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String cacheName, String storageTargetName) {
        final String force = null;
        return this.beginDeleteAsync(resourceGroupName, cacheName, storageTargetName, force).getSyncPoller();
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String cacheName, String storageTargetName, String force, Context context) {
        return this.beginDeleteAsync(resourceGroupName, cacheName, storageTargetName, force, context).getSyncPoller();
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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 cacheName, String storageTargetName, String force) {
        return beginDeleteAsync(resourceGroupName, cacheName, storageTargetName, force)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 cacheName, String storageTargetName) {
        final String force = null;
        return beginDeleteAsync(resourceGroupName, cacheName, storageTargetName, force)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(
        String resourceGroupName, String cacheName, String storageTargetName, String force, Context context) {
        return beginDeleteAsync(resourceGroupName, cacheName, storageTargetName, force, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 cacheName, String storageTargetName) {
        final String force = null;
        deleteAsync(resourceGroupName, cacheName, storageTargetName, force).block();
    }

    /**
     * Removes a Storage Target from a cache. This operation is allowed at any time, but if the cache is down or
     * unhealthy, the actual removal of the Storage Target may be delayed until the cache is healthy again. Note that if
     * the cache has data to flush to the Storage Target, the data will be flushed before the Storage Target will be
     * deleted.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param force Boolean value requesting the force delete operation for a storage target. Force delete discards
     *     unwritten-data in the cache instead of flushing it to back-end storage.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(
        String resourceGroupName, String cacheName, String storageTargetName, String force, Context context) {
        deleteAsync(resourceGroupName, cacheName, storageTargetName, force, context).block();
    }

    /**
     * Returns a Storage Target from a cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 type of the Storage Target along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<StorageTargetInner>> getWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            storageTargetName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns a Storage Target from a cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 type of the Storage Target along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<StorageTargetInner>> getWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                storageTargetName,
                accept,
                context);
    }

    /**
     * Returns a Storage Target from a cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 type of the Storage Target on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<StorageTargetInner> getAsync(String resourceGroupName, String cacheName, String storageTargetName) {
        return getWithResponseAsync(resourceGroupName, cacheName, storageTargetName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Returns a Storage Target from a cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 type of the Storage Target along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<StorageTargetInner> getWithResponse(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        return getWithResponseAsync(resourceGroupName, cacheName, storageTargetName, context).block();
    }

    /**
     * Returns a Storage Target from a cache.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public StorageTargetInner get(String resourceGroupName, String cacheName, String storageTargetName) {
        return getWithResponse(resourceGroupName, cacheName, storageTargetName, Context.NONE).getValue();
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, StorageTargetInner storagetarget) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        if (storagetarget == null) {
            return Mono.error(new IllegalArgumentException("Parameter storagetarget is required and cannot be null."));
        } else {
            storagetarget.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            storageTargetName,
                            storagetarget,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String cacheName,
        String storageTargetName,
        StorageTargetInner storagetarget,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        if (storagetarget == null) {
            return Mono.error(new IllegalArgumentException("Parameter storagetarget is required and cannot be null."));
        } else {
            storagetarget.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                storageTargetName,
                storagetarget,
                accept,
                context);
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 PollerFlux} for polling of type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<StorageTargetInner>, StorageTargetInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String cacheName, String storageTargetName, StorageTargetInner storagetarget) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, cacheName, storageTargetName, storagetarget);
        return this
            .client
            .<StorageTargetInner, StorageTargetInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                StorageTargetInner.class,
                StorageTargetInner.class,
                this.client.getContext());
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 PollerFlux} for polling of type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<StorageTargetInner>, StorageTargetInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String cacheName,
        String storageTargetName,
        StorageTargetInner storagetarget,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, cacheName, storageTargetName, storagetarget, context);
        return this
            .client
            .<StorageTargetInner, StorageTargetInner>getLroResult(
                mono, this.client.getHttpPipeline(), StorageTargetInner.class, StorageTargetInner.class, context);
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 SyncPoller} for polling of type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<StorageTargetInner>, StorageTargetInner> beginCreateOrUpdate(
        String resourceGroupName, String cacheName, String storageTargetName, StorageTargetInner storagetarget) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget)
            .getSyncPoller();
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 SyncPoller} for polling of type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<StorageTargetInner>, StorageTargetInner> beginCreateOrUpdate(
        String resourceGroupName,
        String cacheName,
        String storageTargetName,
        StorageTargetInner storagetarget,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget, context)
            .getSyncPoller();
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<StorageTargetInner> createOrUpdateAsync(
        String resourceGroupName, String cacheName, String storageTargetName, StorageTargetInner storagetarget) {
        return beginCreateOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<StorageTargetInner> createOrUpdateAsync(
        String resourceGroupName,
        String cacheName,
        String storageTargetName,
        StorageTargetInner storagetarget,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public StorageTargetInner createOrUpdate(
        String resourceGroupName, String cacheName, String storageTargetName, StorageTargetInner storagetarget) {
        return createOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget).block();
    }

    /**
     * Create or update a Storage Target. This operation is allowed at any time, but if the cache is down or unhealthy,
     * the actual creation/modification of the Storage Target may be delayed until the cache is healthy again.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @param storagetarget Object containing the definition of a Storage Target.
     * @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 type of the Storage Target.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public StorageTargetInner createOrUpdate(
        String resourceGroupName,
        String cacheName,
        String storageTargetName,
        StorageTargetInner storagetarget,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget, context).block();
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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<Flux<ByteBuffer>>> restoreDefaultsWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .restoreDefaults(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            cacheName,
                            storageTargetName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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<Flux<ByteBuffer>>> restoreDefaultsWithResponseAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (cacheName == null) {
            return Mono.error(new IllegalArgumentException("Parameter cacheName is required and cannot be null."));
        }
        if (storageTargetName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageTargetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .restoreDefaults(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                cacheName,
                storageTargetName,
                accept,
                context);
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginRestoreDefaultsAsync(
        String resourceGroupName, String cacheName, String storageTargetName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            restoreDefaultsWithResponseAsync(resourceGroupName, cacheName, storageTargetName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginRestoreDefaultsAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            restoreDefaultsWithResponseAsync(resourceGroupName, cacheName, storageTargetName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginRestoreDefaults(
        String resourceGroupName, String cacheName, String storageTargetName) {
        return this.beginRestoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName).getSyncPoller();
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginRestoreDefaults(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        return this.beginRestoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName, context).getSyncPoller();
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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> restoreDefaultsAsync(String resourceGroupName, String cacheName, String storageTargetName) {
        return beginRestoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> restoreDefaultsAsync(
        String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        return beginRestoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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 restoreDefaults(String resourceGroupName, String cacheName, String storageTargetName) {
        restoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName).block();
    }

    /**
     * Tells a storage target to restore its settings to their default values.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param cacheName Name of cache. Length of name must not be greater than 80 and chars must be from the
     *     [-0-9a-zA-Z_] char class.
     * @param storageTargetName Name of Storage Target.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void restoreDefaults(String resourceGroupName, String cacheName, String storageTargetName, Context context) {
        restoreDefaultsAsync(resourceGroupName, cacheName, storageTargetName, context).block();
    }

    /**
     * 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 a list of Storage Targets along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<StorageTargetInner>> listByCacheNextSinglePageAsync(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.listByCacheNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<StorageTargetInner>>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 a list of Storage Targets along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<StorageTargetInner>> listByCacheNextSinglePageAsync(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
            .listByCacheNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
