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

package com.azure.resourcemanager.maintenance.implementation;

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

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

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

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

    /**
     * The interface defining all the services for MaintenanceManagementClientApplyUpdates to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "MaintenanceManagemen")
    public interface ApplyUpdatesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}"
                + "/{resourceParentType}/{resourceParentName}/{resourceType}/{resourceName}/providers"
                + "/Microsoft.Maintenance/applyUpdates/{applyUpdateName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ApplyUpdateInner>> getParent(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceParentType") String resourceParentType,
            @PathParam("resourceParentName") String resourceParentName,
            @PathParam("providerName") String providerName,
            @PathParam("resourceType") String resourceType,
            @PathParam("resourceName") String resourceName,
            @PathParam("applyUpdateName") String applyUpdateName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}"
                + "/{resourceName}/providers/Microsoft.Maintenance/applyUpdates/{applyUpdateName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ApplyUpdateInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("providerName") String providerName,
            @PathParam("resourceType") String resourceType,
            @PathParam("resourceName") String resourceName,
            @PathParam("applyUpdateName") String applyUpdateName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}"
                + "/{resourceParentType}/{resourceParentName}/{resourceType}/{resourceName}/providers"
                + "/Microsoft.Maintenance/applyUpdates/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ApplyUpdateInner>> createOrUpdateParent(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("providerName") String providerName,
            @PathParam("resourceParentType") String resourceParentType,
            @PathParam("resourceParentName") String resourceParentName,
            @PathParam("resourceType") String resourceType,
            @PathParam("resourceName") String resourceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}"
                + "/{resourceName}/providers/Microsoft.Maintenance/applyUpdates/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ApplyUpdateInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("providerName") String providerName,
            @PathParam("resourceType") String resourceType,
            @PathParam("resourceName") String resourceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Maintenance/applyUpdates")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ListApplyUpdate>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Track Updates to resource with parent
     *
     * <p>Track maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> getParentWithResponseAsync(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (resourceParentType == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentType is required and cannot be null."));
        }
        if (resourceParentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (applyUpdateName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applyUpdateName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getParent(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            resourceParentType,
                            resourceParentName,
                            providerName,
                            resourceType,
                            resourceName,
                            applyUpdateName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Track Updates to resource with parent
     *
     * <p>Track maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> getParentWithResponseAsync(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (resourceParentType == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentType is required and cannot be null."));
        }
        if (resourceParentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (applyUpdateName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applyUpdateName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getParent(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                resourceParentType,
                resourceParentName,
                providerName,
                resourceType,
                resourceName,
                applyUpdateName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Track Updates to resource with parent
     *
     * <p>Track maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ApplyUpdateInner> getParentAsync(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        return getParentWithResponseAsync(
                resourceGroupName,
                resourceParentType,
                resourceParentName,
                providerName,
                resourceType,
                resourceName,
                applyUpdateName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Track Updates to resource with parent
     *
     * <p>Track maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplyUpdateInner> getParentWithResponse(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        return getParentWithResponseAsync(
                resourceGroupName,
                resourceParentType,
                resourceParentName,
                providerName,
                resourceType,
                resourceName,
                applyUpdateName,
                context)
            .block();
    }

    /**
     * Track Updates to resource with parent
     *
     * <p>Track maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplyUpdateInner getParent(
        String resourceGroupName,
        String resourceParentType,
        String resourceParentName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        return getParentWithResponse(
                resourceGroupName,
                resourceParentType,
                resourceParentName,
                providerName,
                resourceType,
                resourceName,
                applyUpdateName,
                Context.NONE)
            .getValue();
    }

    /**
     * Track Updates to resource
     *
     * <p>Track maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> getWithResponseAsync(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (applyUpdateName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applyUpdateName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            providerName,
                            resourceType,
                            resourceName,
                            applyUpdateName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Track Updates to resource
     *
     * <p>Track maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> getWithResponseAsync(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (applyUpdateName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applyUpdateName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                providerName,
                resourceType,
                resourceName,
                applyUpdateName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Track Updates to resource
     *
     * <p>Track maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ApplyUpdateInner> getAsync(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        return getWithResponseAsync(resourceGroupName, providerName, resourceType, resourceName, applyUpdateName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Track Updates to resource
     *
     * <p>Track maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplyUpdateInner> getWithResponse(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName,
        Context context) {
        return getWithResponseAsync(
                resourceGroupName, providerName, resourceType, resourceName, applyUpdateName, context)
            .block();
    }

    /**
     * Track Updates to resource
     *
     * <p>Track maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @param applyUpdateName applyUpdate Id.
     * @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 apply Update request.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplyUpdateInner get(
        String resourceGroupName,
        String providerName,
        String resourceType,
        String resourceName,
        String applyUpdateName) {
        return getWithResponse(
                resourceGroupName, providerName, resourceType, resourceName, applyUpdateName, Context.NONE)
            .getValue();
    }

    /**
     * Apply Updates to resource with parent
     *
     * <p>Apply maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> createOrUpdateParentWithResponseAsync(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceParentType == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentType is required and cannot be null."));
        }
        if (resourceParentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateParent(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            providerName,
                            resourceParentType,
                            resourceParentName,
                            resourceType,
                            resourceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Apply Updates to resource with parent
     *
     * <p>Apply maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> createOrUpdateParentWithResponseAsync(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceParentType == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentType is required and cannot be null."));
        }
        if (resourceParentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceParentName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateParent(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                providerName,
                resourceParentType,
                resourceParentName,
                resourceType,
                resourceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Apply Updates to resource with parent
     *
     * <p>Apply maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ApplyUpdateInner> createOrUpdateParentAsync(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName) {
        return createOrUpdateParentWithResponseAsync(
                resourceGroupName, providerName, resourceParentType, resourceParentName, resourceType, resourceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Apply Updates to resource with parent
     *
     * <p>Apply maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplyUpdateInner> createOrUpdateParentWithResponse(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName,
        Context context) {
        return createOrUpdateParentWithResponseAsync(
                resourceGroupName,
                providerName,
                resourceParentType,
                resourceParentName,
                resourceType,
                resourceName,
                context)
            .block();
    }

    /**
     * Apply Updates to resource with parent
     *
     * <p>Apply maintenance updates to resource with parent.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceParentType Resource parent type.
     * @param resourceParentName Resource parent identifier.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplyUpdateInner createOrUpdateParent(
        String resourceGroupName,
        String providerName,
        String resourceParentType,
        String resourceParentName,
        String resourceType,
        String resourceName) {
        return createOrUpdateParentWithResponse(
                resourceGroupName,
                providerName,
                resourceParentType,
                resourceParentName,
                resourceType,
                resourceName,
                Context.NONE)
            .getValue();
    }

    /**
     * Apply Updates to resource
     *
     * <p>Apply maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String providerName, String resourceType, String resourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            providerName,
                            resourceType,
                            resourceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Apply Updates to resource
     *
     * <p>Apply maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplyUpdateInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String providerName, String resourceType, String resourceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (providerName == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerName is required and cannot be null."));
        }
        if (resourceType == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceType is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                providerName,
                resourceType,
                resourceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Apply Updates to resource
     *
     * <p>Apply maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ApplyUpdateInner> createOrUpdateAsync(
        String resourceGroupName, String providerName, String resourceType, String resourceName) {
        return createOrUpdateWithResponseAsync(resourceGroupName, providerName, resourceType, resourceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Apply Updates to resource
     *
     * <p>Apply maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplyUpdateInner> createOrUpdateWithResponse(
        String resourceGroupName, String providerName, String resourceType, String resourceName, Context context) {
        return createOrUpdateWithResponseAsync(resourceGroupName, providerName, resourceType, resourceName, context)
            .block();
    }

    /**
     * Apply Updates to resource
     *
     * <p>Apply maintenance updates to resource.
     *
     * @param resourceGroupName Resource group name.
     * @param providerName Resource provider name.
     * @param resourceType Resource type.
     * @param resourceName Resource identifier.
     * @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 apply Update request.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplyUpdateInner createOrUpdate(
        String resourceGroupName, String providerName, String resourceType, String resourceName) {
        return createOrUpdateWithResponse(resourceGroupName, providerName, resourceType, resourceName, Context.NONE)
            .getValue();
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplyUpdateInner>> listSinglePageAsync() {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<ApplyUpdateInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplyUpdateInner>> listSinglePageAsync(Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null));
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ApplyUpdateInner> listAsync() {
        return new PagedFlux<>(() -> listSinglePageAsync());
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ApplyUpdateInner> listAsync(Context context) {
        return new PagedFlux<>(() -> listSinglePageAsync(context));
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ApplyUpdateInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * Get Configuration records within a subscription.
     *
     * @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 configuration records within a subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ApplyUpdateInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }
}
