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

package azure.resourcemanager.resources.implementation;

import azure.resourcemanager.resources.fluent.ExtensionsResourcesClient;
import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner;
import azure.resourcemanager.resources.implementation.models.ExtensionsResourceListResult;
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.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.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 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 ExtensionsResourcesClient.
 */
public final class ExtensionsResourcesClientImpl implements ExtensionsResourcesClient {
    /**
     * The proxy service used to perform REST calls.
     */
    private final ExtensionsResourcesService service;

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

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

    /**
     * The interface defining all the services for ResourcesClientExtensionsResources to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ResourcesClientExten")
    public interface ExtensionsResourcesService {
        @Headers({ "Content-Type: application/json" })
        @Get("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ExtensionsResourceInner>> get(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam(value = "resourceUri", encoded = true) String resourceUri,
            @PathParam("extensionsResourceName") String extensionsResourceName, @HeaderParam("Accept") String accept,
            Context context);

        @Put("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam(value = "resourceUri", encoded = true) String resourceUri,
            @PathParam("extensionsResourceName") String extensionsResourceName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExtensionsResourceInner resource, Context context);

        @Patch("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ExtensionsResourceInner>> update(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam(value = "resourceUri", encoded = true) String resourceUri,
            @PathParam("extensionsResourceName") String extensionsResourceName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExtensionsResourceInner properties, Context context);

        @Headers({ "Content-Type: application/json" })
        @Delete("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}")
        @ExpectedResponses({ 200, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam(value = "resourceUri", encoded = true) String resourceUri,
            @PathParam("extensionsResourceName") String extensionsResourceName, @HeaderParam("Accept") String accept,
            Context context);

        @Headers({ "Content-Type: application/json" })
        @Get("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources")
        @ExpectedResponses({ 200 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ExtensionsResourceListResult>> listByScope(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam(value = "resourceUri", encoded = true) String resourceUri, @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Get a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 ExtensionsResource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionsResourceInner>> getWithResponseAsync(String resourceUri,
        String extensionsResourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
                extensionsResourceName, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 ExtensionsResource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionsResourceInner>> getWithResponseAsync(String resourceUri,
        String extensionsResourceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.get(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, extensionsResourceName,
            accept, context);
    }

    /**
     * Get a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 ExtensionsResource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionsResourceInner> getAsync(String resourceUri, String extensionsResourceName) {
        return getWithResponseAsync(resourceUri, extensionsResourceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 ExtensionsResource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ExtensionsResourceInner> getWithResponse(String resourceUri, String extensionsResourceName,
        Context context) {
        return getWithResponseAsync(resourceUri, extensionsResourceName, context).block();
    }

    /**
     * Get a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 ExtensionsResource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionsResourceInner get(String resourceUri, String extensionsResourceName) {
        return getWithResponse(resourceUri, extensionsResourceName, Context.NONE).getValue();
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type
     * along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(String resourceUri,
        String extensionsResourceName, ExtensionsResourceInner resource) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        if (resource == null) {
            return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null."));
        } else {
            resource.validate();
        }
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(),
                resourceUri, extensionsResourceName, contentType, accept, resource, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type
     * along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(String resourceUri,
        String extensionsResourceName, ExtensionsResourceInner resource, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        if (resource == null) {
            return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null."));
        } else {
            resource.validate();
        }
        final String contentType = "application/json";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
            extensionsResourceName, contentType, accept, resource, context);
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionsResourceInner>, ExtensionsResourceInner>
        beginCreateOrUpdateAsync(String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource) {
        Mono<Response<Flux<ByteBuffer>>> mono
            = createOrUpdateWithResponseAsync(resourceUri, extensionsResourceName, resource);
        return this.client.<ExtensionsResourceInner, ExtensionsResourceInner>getLroResult(mono,
            this.client.getHttpPipeline(), ExtensionsResourceInner.class, ExtensionsResourceInner.class,
            this.client.getContext());
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionsResourceInner>, ExtensionsResourceInner> beginCreateOrUpdateAsync(
        String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono
            = createOrUpdateWithResponseAsync(resourceUri, extensionsResourceName, resource, context);
        return this.client.<ExtensionsResourceInner, ExtensionsResourceInner>getLroResult(mono,
            this.client.getHttpPipeline(), ExtensionsResourceInner.class, ExtensionsResourceInner.class, context);
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionsResourceInner>, ExtensionsResourceInner>
        beginCreateOrUpdate(String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource) {
        return this.beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource).getSyncPoller();
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionsResourceInner>, ExtensionsResourceInner> beginCreateOrUpdate(
        String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource, Context context) {
        return this.beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).getSyncPoller();
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionsResourceInner> createOrUpdateAsync(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner resource) {
        return beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionsResourceInner> createOrUpdateAsync(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner resource, Context context) {
        return beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner resource) {
        return createOrUpdateAsync(resourceUri, extensionsResourceName, resource).block();
    }

    /**
     * Create a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param resource Resource create parameters.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner resource, Context context) {
        return createOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).block();
    }

    /**
     * Update a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param properties The resource properties to be updated.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type
     * along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionsResourceInner>> updateWithResponseAsync(String resourceUri,
        String extensionsResourceName, ExtensionsResourceInner properties) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.update(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
                extensionsResourceName, contentType, accept, properties, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param properties The resource properties to be updated.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type
     * along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionsResourceInner>> updateWithResponseAsync(String resourceUri,
        String extensionsResourceName, ExtensionsResourceInner properties, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String contentType = "application/json";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.update(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
            extensionsResourceName, contentType, accept, properties, context);
    }

    /**
     * Update a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param properties The resource properties to be updated.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionsResourceInner> updateAsync(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner properties) {
        return updateWithResponseAsync(resourceUri, extensionsResourceName, properties)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param properties The resource properties to be updated.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type
     * along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ExtensionsResourceInner> updateWithResponse(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner properties, Context context) {
        return updateWithResponseAsync(resourceUri, extensionsResourceName, properties, context).block();
    }

    /**
     * Update a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param properties The resource properties to be updated.
     * @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 concrete extension resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionsResourceInner update(String resourceUri, String extensionsResourceName,
        ExtensionsResourceInner properties) {
        return updateWithResponse(resourceUri, extensionsResourceName, properties, Context.NONE).getValue();
    }

    /**
     * Delete a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String resourceUri, String extensionsResourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
                extensionsResourceName, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String resourceUri, String extensionsResourceName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        if (extensionsResourceName == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.delete(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri,
            extensionsResourceName, accept, context);
    }

    /**
     * Delete a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 resourceUri, String extensionsResourceName) {
        return deleteWithResponseAsync(resourceUri, extensionsResourceName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String resourceUri, String extensionsResourceName, Context context) {
        return deleteWithResponseAsync(resourceUri, extensionsResourceName, context).block();
    }

    /**
     * Delete a ExtensionsResource.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param extensionsResourceName The name of the ExtensionsResource.
     * @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 resourceUri, String extensionsResourceName) {
        deleteWithResponse(resourceUri, extensionsResourceName, Context.NONE);
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionsResourceInner>> listByScopeSinglePageAsync(String resourceUri) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listByScope(this.client.getEndpoint(), this.client.getApiVersion(),
                resourceUri, accept, context))
            .<PagedResponse<ExtensionsResourceInner>>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()));
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionsResourceInner>> listByScopeSinglePageAsync(String resourceUri,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono.error(
                new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceUri == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.listByScope(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, accept, context)
            .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
                res.getValue().value(), res.getValue().nextLink(), null));
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ExtensionsResourceInner> listByScopeAsync(String resourceUri) {
        return new PagedFlux<>(() -> listByScopeSinglePageAsync(resourceUri),
            nextLink -> listByScopeNextSinglePageAsync(nextLink));
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ExtensionsResourceInner> listByScopeAsync(String resourceUri, Context context) {
        return new PagedFlux<>(() -> listByScopeSinglePageAsync(resourceUri, context),
            nextLink -> listByScopeNextSinglePageAsync(nextLink, context));
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ExtensionsResourceInner> listByScope(String resourceUri) {
        return new PagedIterable<>(listByScopeAsync(resourceUri));
    }

    /**
     * List ExtensionsResource resources by parent.
     * 
     * @param resourceUri The fully qualified Azure Resource manager identifier of the resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ExtensionsResourceInner> listByScope(String resourceUri, Context context) {
        return new PagedIterable<>(listByScopeAsync(resourceUri, context));
    }

    /**
     * Get the next page of items.
     * 
     * @param nextLink The URL to get the next list of items.
     * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionsResourceInner>> listByScopeNextSinglePageAsync(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.listByScopeNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ExtensionsResourceInner>>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.
     * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful
     * completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionsResourceInner>> listByScopeNextSinglePageAsync(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.listByScopeNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
                res.getValue().value(), res.getValue().nextLink(), null));
    }
}
