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

package com.azure.resourcemanager.security.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.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.security.fluent.WorkspaceSettingsClient;
import com.azure.resourcemanager.security.fluent.models.WorkspaceSettingInner;
import com.azure.resourcemanager.security.models.WorkspaceSettingList;
import reactor.core.publisher.Mono;

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Put("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<WorkspaceSettingInner>> create(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("workspaceSettingName") String workspaceSettingName,
            @BodyParam("application/json") WorkspaceSettingInner workspaceSetting,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/subscriptions/{subscriptionId}/providers/Microsoft.Security/workspaceSettings/{workspaceSettingName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<WorkspaceSettingInner>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("workspaceSettingName") String workspaceSettingName,
            @BodyParam("application/json") WorkspaceSettingInner workspaceSetting,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<WorkspaceSettingInner>> 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 apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), accept, context))
            .<PagedResponse<WorkspaceSettingInner>>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()));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<WorkspaceSettingInner>> 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 apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<WorkspaceSettingInner> listAsync() {
        return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<WorkspaceSettingInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<WorkspaceSettingInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<WorkspaceSettingInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> getWithResponseAsync(String workspaceSettingName) {
        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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            workspaceSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> getWithResponseAsync(String workspaceSettingName, 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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                workspaceSettingName,
                accept,
                context);
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 configures where to store the OMS agent data for workspaces under a scope on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<WorkspaceSettingInner> getAsync(String workspaceSettingName) {
        return getWithResponseAsync(workspaceSettingName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<WorkspaceSettingInner> getWithResponse(String workspaceSettingName, Context context) {
        return getWithResponseAsync(workspaceSettingName, context).block();
    }

    /**
     * Settings about where we should store your security data and logs. If the result is empty, it means that no
     * custom-workspace configuration was set.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 configures where to store the OMS agent data for workspaces under a scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public WorkspaceSettingInner get(String workspaceSettingName) {
        return getWithResponse(workspaceSettingName, Context.NONE).getValue();
    }

    /**
     * creating settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> createWithResponseAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        if (workspaceSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSetting is required and cannot be null."));
        } else {
            workspaceSetting.validate();
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            workspaceSettingName,
                            workspaceSetting,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * creating settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> createWithResponseAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting, 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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        if (workspaceSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSetting is required and cannot be null."));
        } else {
            workspaceSetting.validate();
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                workspaceSettingName,
                workspaceSetting,
                accept,
                context);
    }

    /**
     * creating settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<WorkspaceSettingInner> createAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        return createWithResponseAsync(workspaceSettingName, workspaceSetting)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * creating settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<WorkspaceSettingInner> createWithResponse(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting, Context context) {
        return createWithResponseAsync(workspaceSettingName, workspaceSetting, context).block();
    }

    /**
     * creating settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public WorkspaceSettingInner create(String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        return createWithResponse(workspaceSettingName, workspaceSetting, Context.NONE).getValue();
    }

    /**
     * Settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> updateWithResponseAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        if (workspaceSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSetting is required and cannot be null."));
        } else {
            workspaceSetting.validate();
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            workspaceSettingName,
                            workspaceSetting,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<WorkspaceSettingInner>> updateWithResponseAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting, 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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        if (workspaceSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSetting is required and cannot be null."));
        } else {
            workspaceSetting.validate();
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                workspaceSettingName,
                workspaceSetting,
                accept,
                context);
    }

    /**
     * Settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<WorkspaceSettingInner> updateAsync(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        return updateWithResponseAsync(workspaceSettingName, workspaceSetting)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<WorkspaceSettingInner> updateWithResponse(
        String workspaceSettingName, WorkspaceSettingInner workspaceSetting, Context context) {
        return updateWithResponseAsync(workspaceSettingName, workspaceSetting, context).block();
    }

    /**
     * Settings about where we should store your security data and logs.
     *
     * @param workspaceSettingName Name of the security setting.
     * @param workspaceSetting Security data setting object.
     * @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 configures where to store the OMS agent data for workspaces under a scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public WorkspaceSettingInner update(String workspaceSettingName, WorkspaceSettingInner workspaceSetting) {
        return updateWithResponse(workspaceSettingName, workspaceSetting, Context.NONE).getValue();
    }

    /**
     * Deletes the custom workspace settings for this subscription. new VMs will report to the default workspace.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 workspaceSettingName) {
        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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            workspaceSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the custom workspace settings for this subscription. new VMs will report to the default workspace.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 workspaceSettingName, 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 (workspaceSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter workspaceSettingName is required and cannot be null."));
        }
        final String apiVersion = "2017-08-01-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                workspaceSettingName,
                accept,
                context);
    }

    /**
     * Deletes the custom workspace settings for this subscription. new VMs will report to the default workspace.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 workspaceSettingName) {
        return deleteWithResponseAsync(workspaceSettingName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes the custom workspace settings for this subscription. new VMs will report to the default workspace.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 workspaceSettingName, Context context) {
        return deleteWithResponseAsync(workspaceSettingName, context).block();
    }

    /**
     * Deletes the custom workspace settings for this subscription. new VMs will report to the default workspace.
     *
     * @param workspaceSettingName Name of the security setting.
     * @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 workspaceSettingName) {
        deleteWithResponse(workspaceSettingName, Context.NONE);
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<WorkspaceSettingInner>> listNextSinglePageAsync(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.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<WorkspaceSettingInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of workspace settings response along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<WorkspaceSettingInner>> listNextSinglePageAsync(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
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
