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

package com.azure.resourcemanager.managementgroups.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.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.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.managementgroups.fluent.HierarchySettingsOperationsClient;
import com.azure.resourcemanager.managementgroups.fluent.models.HierarchySettingsInner;
import com.azure.resourcemanager.managementgroups.fluent.models.HierarchySettingsListInner;
import com.azure.resourcemanager.managementgroups.models.CreateOrUpdateSettingsRequest;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for ManagementGroupsApiHierarchySettingsOperations to be used by the
     * proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "ManagementGroupsApiH")
    public interface HierarchySettingsOperationsService {
        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Management/managementGroups/{groupId}/settings")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HierarchySettingsListInner>> list(
            @HostParam("$host") String endpoint,
            @PathParam("groupId") String groupId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Management/managementGroups/{groupId}/settings/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HierarchySettingsInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("groupId") String groupId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/providers/Microsoft.Management/managementGroups/{groupId}/settings/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HierarchySettingsInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("groupId") String groupId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CreateOrUpdateSettingsRequest createTenantSettingsRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/providers/Microsoft.Management/managementGroups/{groupId}/settings/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HierarchySettingsInner>> update(
            @HostParam("$host") String endpoint,
            @PathParam("groupId") String groupId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CreateOrUpdateSettingsRequest createTenantSettingsRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/providers/Microsoft.Management/managementGroups/{groupId}/settings/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("groupId") String groupId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Gets all the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 all the hierarchy settings defined at the Management Group level along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsListInner>> listWithResponseAsync(String groupId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.list(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets all the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 all the hierarchy settings defined at the Management Group level along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsListInner>> listWithResponseAsync(String groupId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.list(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context);
    }

    /**
     * Gets all the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 all the hierarchy settings defined at the Management Group level on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HierarchySettingsListInner> listAsync(String groupId) {
        return listWithResponseAsync(groupId).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets all the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 all the hierarchy settings defined at the Management Group level along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HierarchySettingsListInner> listWithResponse(String groupId, Context context) {
        return listWithResponseAsync(groupId, context).block();
    }

    /**
     * Gets all the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 all the hierarchy settings defined at the Management Group level.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HierarchySettingsListInner list(String groupId) {
        return listWithResponse(groupId, Context.NONE).getValue();
    }

    /**
     * Gets the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 the hierarchy settings defined at the Management Group level along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> getWithResponseAsync(String groupId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.get(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 the hierarchy settings defined at the Management Group level along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> getWithResponseAsync(String groupId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.get(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context);
    }

    /**
     * Gets the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 the hierarchy settings defined at the Management Group level on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HierarchySettingsInner> getAsync(String groupId) {
        return getWithResponseAsync(groupId).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 the hierarchy settings defined at the Management Group level along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HierarchySettingsInner> getWithResponse(String groupId, Context context) {
        return getWithResponseAsync(groupId, context).block();
    }

    /**
     * Gets the hierarchy settings defined at the Management Group level. Settings can only be set on the root
     * Management Group of the hierarchy.
     *
     * @param groupId Management Group 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 the hierarchy settings defined at the Management Group level.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HierarchySettingsInner get(String groupId) {
        return getWithResponse(groupId, Context.NONE).getValue();
    }

    /**
     * Creates or updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> createOrUpdateWithResponseAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        if (createTenantSettingsRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createTenantSettingsRequest is required and cannot be null."));
        } else {
            createTenantSettingsRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            groupId,
                            this.client.getApiVersion(),
                            createTenantSettingsRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> createOrUpdateWithResponseAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        if (createTenantSettingsRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createTenantSettingsRequest is required and cannot be null."));
        } else {
            createTenantSettingsRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                groupId,
                this.client.getApiVersion(),
                createTenantSettingsRequest,
                accept,
                context);
    }

    /**
     * Creates or updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HierarchySettingsInner> createOrUpdateAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        return createOrUpdateWithResponseAsync(groupId, createTenantSettingsRequest)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HierarchySettingsInner> createOrUpdateWithResponse(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest, Context context) {
        return createOrUpdateWithResponseAsync(groupId, createTenantSettingsRequest, context).block();
    }

    /**
     * Creates or updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HierarchySettingsInner createOrUpdate(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        return createOrUpdateWithResponse(groupId, createTenantSettingsRequest, Context.NONE).getValue();
    }

    /**
     * Updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> updateWithResponseAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        if (createTenantSettingsRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createTenantSettingsRequest is required and cannot be null."));
        } else {
            createTenantSettingsRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            groupId,
                            this.client.getApiVersion(),
                            createTenantSettingsRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HierarchySettingsInner>> updateWithResponseAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        if (createTenantSettingsRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createTenantSettingsRequest is required and cannot be null."));
        } else {
            createTenantSettingsRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                groupId,
                this.client.getApiVersion(),
                createTenantSettingsRequest,
                accept,
                context);
    }

    /**
     * Updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HierarchySettingsInner> updateAsync(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        return updateWithResponseAsync(groupId, createTenantSettingsRequest)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HierarchySettingsInner> updateWithResponse(
        String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest, Context context) {
        return updateWithResponseAsync(groupId, createTenantSettingsRequest, context).block();
    }

    /**
     * Updates the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group ID.
     * @param createTenantSettingsRequest Tenant level settings request parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return settings defined at the Management Group scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HierarchySettingsInner update(String groupId, CreateOrUpdateSettingsRequest createTenantSettingsRequest) {
        return updateWithResponse(groupId, createTenantSettingsRequest, Context.NONE).getValue();
    }

    /**
     * Deletes the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group 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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String groupId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.delete(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group 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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String groupId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.delete(this.client.getEndpoint(), groupId, this.client.getApiVersion(), accept, context);
    }

    /**
     * Deletes the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String groupId) {
        return deleteWithResponseAsync(groupId).flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group 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 the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String groupId, Context context) {
        return deleteWithResponseAsync(groupId, context).block();
    }

    /**
     * Deletes the hierarchy settings defined at the Management Group level.
     *
     * @param groupId Management Group 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String groupId) {
        deleteWithResponse(groupId, Context.NONE);
    }
}
