// 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.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.security.fluent.IngestionSettingsClient;
import com.azure.resourcemanager.security.fluent.models.ConnectionStringsInner;
import com.azure.resourcemanager.security.fluent.models.IngestionSettingInner;
import com.azure.resourcemanager.security.fluent.models.IngestionSettingTokenInner;
import com.azure.resourcemanager.security.models.IngestionSettingList;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for SecurityCenterIngestionSettings to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "SecurityCenterIngest")
    public interface IngestionSettingsService {
        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Security/ingestionSettings")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<IngestionSettingList>> 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/ingestionSettings/{ingestionSettingName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<IngestionSettingInner>> get(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("ingestionSettingName") String ingestionSettingName,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

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

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<IngestionSettingInner>> 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 = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), accept, context))
            .<PagedResponse<IngestionSettingInner>>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 for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<IngestionSettingInner>> 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 = "2021-01-15-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 for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<IngestionSettingInner> listAsync() {
        return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<IngestionSettingInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<IngestionSettingInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the 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 list of ingestion settings as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<IngestionSettingInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingInner>> getWithResponseAsync(String ingestionSettingName) {
        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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            ingestionSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingInner>> getWithResponseAsync(String ingestionSettingName, 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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                ingestionSettingName,
                accept,
                context);
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IngestionSettingInner> getAsync(String ingestionSettingName) {
        return getWithResponseAsync(ingestionSettingName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<IngestionSettingInner> getWithResponse(String ingestionSettingName, Context context) {
        return getWithResponseAsync(ingestionSettingName, context).block();
    }

    /**
     * Settings for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IngestionSettingInner get(String ingestionSettingName) {
        return getWithResponse(ingestionSettingName, Context.NONE).getValue();
    }

    /**
     * Create setting for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion setting.
     * @param ingestionSetting Ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingInner>> createWithResponseAsync(
        String ingestionSettingName, IngestionSettingInner ingestionSetting) {
        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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        if (ingestionSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSetting is required and cannot be null."));
        } else {
            ingestionSetting.validate();
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            ingestionSettingName,
                            ingestionSetting,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create setting for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion setting.
     * @param ingestionSetting Ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingInner>> createWithResponseAsync(
        String ingestionSettingName, IngestionSettingInner ingestionSetting, 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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        if (ingestionSetting == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSetting is required and cannot be null."));
        } else {
            ingestionSetting.validate();
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                ingestionSettingName,
                ingestionSetting,
                accept,
                context);
    }

    /**
     * Create setting for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion setting.
     * @param ingestionSetting Ingestion 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 how to correlate scan data and logs with resources associated with the subscription on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IngestionSettingInner> createAsync(
        String ingestionSettingName, IngestionSettingInner ingestionSetting) {
        return createWithResponseAsync(ingestionSettingName, ingestionSetting)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create setting for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion setting.
     * @param ingestionSetting Ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<IngestionSettingInner> createWithResponse(
        String ingestionSettingName, IngestionSettingInner ingestionSetting, Context context) {
        return createWithResponseAsync(ingestionSettingName, ingestionSetting, context).block();
    }

    /**
     * Create setting for ingesting security data and logs to correlate with resources associated with the subscription.
     *
     * @param ingestionSettingName Name of the ingestion setting.
     * @param ingestionSetting Ingestion 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 how to correlate scan data and logs with resources associated with the subscription.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IngestionSettingInner create(String ingestionSettingName, IngestionSettingInner ingestionSetting) {
        return createWithResponse(ingestionSettingName, ingestionSetting, Context.NONE).getValue();
    }

    /**
     * Deletes the ingestion settings for this subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 ingestionSettingName) {
        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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            ingestionSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the ingestion settings for this subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 ingestionSettingName, 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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                ingestionSettingName,
                accept,
                context);
    }

    /**
     * Deletes the ingestion settings for this subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 ingestionSettingName) {
        return deleteWithResponseAsync(ingestionSettingName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes the ingestion settings for this subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 ingestionSettingName, Context context) {
        return deleteWithResponseAsync(ingestionSettingName, context).block();
    }

    /**
     * Deletes the ingestion settings for this subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 ingestionSettingName) {
        deleteWithResponse(ingestionSettingName, Context.NONE);
    }

    /**
     * Returns the token that is used for correlating ingested telemetry with the resources in the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingTokenInner>> listTokensWithResponseAsync(String ingestionSettingName) {
        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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listTokens(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            ingestionSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns the token that is used for correlating ingested telemetry with the resources in the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IngestionSettingTokenInner>> listTokensWithResponseAsync(
        String ingestionSettingName, 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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listTokens(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                ingestionSettingName,
                accept,
                context);
    }

    /**
     * Returns the token that is used for correlating ingested telemetry with the resources in the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IngestionSettingTokenInner> listTokensAsync(String ingestionSettingName) {
        return listTokensWithResponseAsync(ingestionSettingName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Returns the token that is used for correlating ingested telemetry with the resources in the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription along with
     *     {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<IngestionSettingTokenInner> listTokensWithResponse(String ingestionSettingName, Context context) {
        return listTokensWithResponseAsync(ingestionSettingName, context).block();
    }

    /**
     * Returns the token that is used for correlating ingested telemetry with the resources in the subscription.
     *
     * @param ingestionSettingName Name of the ingestion 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 how to correlate scan data and logs with resources associated with the subscription.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IngestionSettingTokenInner listTokens(String ingestionSettingName) {
        return listTokensWithResponse(ingestionSettingName, Context.NONE).getValue();
    }

    /**
     * Connection strings for ingesting security scan logs and data.
     *
     * @param ingestionSettingName Name of the ingestion 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 connection string for ingesting security data and logs along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ConnectionStringsInner>> listConnectionStringsWithResponseAsync(String ingestionSettingName) {
        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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listConnectionStrings(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            ingestionSettingName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Connection strings for ingesting security scan logs and data.
     *
     * @param ingestionSettingName Name of the ingestion 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 connection string for ingesting security data and logs along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ConnectionStringsInner>> listConnectionStringsWithResponseAsync(
        String ingestionSettingName, 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 (ingestionSettingName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter ingestionSettingName is required and cannot be null."));
        }
        final String apiVersion = "2021-01-15-preview";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listConnectionStrings(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                ingestionSettingName,
                accept,
                context);
    }

    /**
     * Connection strings for ingesting security scan logs and data.
     *
     * @param ingestionSettingName Name of the ingestion 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 connection string for ingesting security data and logs on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ConnectionStringsInner> listConnectionStringsAsync(String ingestionSettingName) {
        return listConnectionStringsWithResponseAsync(ingestionSettingName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Connection strings for ingesting security scan logs and data.
     *
     * @param ingestionSettingName Name of the ingestion 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 connection string for ingesting security data and logs along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ConnectionStringsInner> listConnectionStringsWithResponse(
        String ingestionSettingName, Context context) {
        return listConnectionStringsWithResponseAsync(ingestionSettingName, context).block();
    }

    /**
     * Connection strings for ingesting security scan logs and data.
     *
     * @param ingestionSettingName Name of the ingestion 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 connection string for ingesting security data and logs.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ConnectionStringsInner listConnectionStrings(String ingestionSettingName) {
        return listConnectionStringsWithResponse(ingestionSettingName, Context.NONE).getValue();
    }

    /**
     * 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 ingestion settings along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<IngestionSettingInner>> 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<IngestionSettingInner>>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 ingestion settings along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<IngestionSettingInner>> 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));
    }
}
