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

package com.azure.resourcemanager.selfhelp.implementation;

import com.azure.core.annotation.BodyParam;
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.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.selfhelp.fluent.DiagnosticsClient;
import com.azure.resourcemanager.selfhelp.fluent.models.CheckNameAvailabilityResponseInner;
import com.azure.resourcemanager.selfhelp.fluent.models.DiagnosticResourceInner;
import com.azure.resourcemanager.selfhelp.models.CheckNameAvailabilityRequest;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for HelpRPDiagnostics to be used by the proxy service to perform REST
     * calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HelpRPDiagnostics")
    public interface DiagnosticsService {
        @Headers({"Content-Type: application/json"})
        @Post("/{scope}/providers/Microsoft.Help/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailability(
            @HostParam("$host") String endpoint,
            @PathParam(value = "scope", encoded = true) String scope,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CheckNameAvailabilityRequest checkNameAvailabilityRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/{scope}/providers/Microsoft.Help/diagnostics/{diagnosticsResourceName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> create(
            @HostParam("$host") String endpoint,
            @PathParam(value = "scope", encoded = true) String scope,
            @PathParam("diagnosticsResourceName") String diagnosticsResourceName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") DiagnosticResourceInner diagnosticResourceRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{scope}/providers/Microsoft.Help/diagnostics/{diagnosticsResourceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<DiagnosticResourceInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam(value = "scope", encoded = true) String scope,
            @PathParam("diagnosticsResourceName") String diagnosticsResourceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * This API is used to check the uniqueness of a resource name used for a diagnostic check.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param checkNameAvailabilityRequest The required parameters for availability check.
     * @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 response for whether the requested resource name is available or not along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest != null) {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkNameAvailability(
                            this.client.getEndpoint(),
                            scope,
                            this.client.getApiVersion(),
                            checkNameAvailabilityRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * This API is used to check the uniqueness of a resource name used for a diagnostic check.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param checkNameAvailabilityRequest The required parameters for availability check.
     * @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 response for whether the requested resource name is available or not along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest != null) {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkNameAvailability(
                this.client.getEndpoint(),
                scope,
                this.client.getApiVersion(),
                checkNameAvailabilityRequest,
                accept,
                context);
    }

    /**
     * This API is used to check the uniqueness of a resource name used for a diagnostic check.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @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 response for whether the requested resource name is available or not on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CheckNameAvailabilityResponseInner> checkNameAvailabilityAsync(String scope) {
        final CheckNameAvailabilityRequest checkNameAvailabilityRequest = null;
        return checkNameAvailabilityWithResponseAsync(scope, checkNameAvailabilityRequest)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * This API is used to check the uniqueness of a resource name used for a diagnostic check.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param checkNameAvailabilityRequest The required parameters for availability check.
     * @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 response for whether the requested resource name is available or not along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckNameAvailabilityResponseInner> checkNameAvailabilityWithResponse(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        return checkNameAvailabilityWithResponseAsync(scope, checkNameAvailabilityRequest, context).block();
    }

    /**
     * This API is used to check the uniqueness of a resource name used for a diagnostic check.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @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 response for whether the requested resource name is available or not.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckNameAvailabilityResponseInner checkNameAvailability(String scope) {
        final CheckNameAvailabilityRequest checkNameAvailabilityRequest = null;
        return checkNameAvailabilityWithResponse(scope, checkNameAvailabilityRequest, Context.NONE).getValue();
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @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 diagnostic resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String scope, String diagnosticsResourceName, DiagnosticResourceInner diagnosticResourceRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (diagnosticsResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter diagnosticsResourceName is required and cannot be null."));
        }
        if (diagnosticResourceRequest != null) {
            diagnosticResourceRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            scope,
                            diagnosticsResourceName,
                            this.client.getApiVersion(),
                            diagnosticResourceRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @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 diagnostic resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String scope,
        String diagnosticsResourceName,
        DiagnosticResourceInner diagnosticResourceRequest,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (diagnosticsResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter diagnosticsResourceName is required and cannot be null."));
        }
        if (diagnosticResourceRequest != null) {
            diagnosticResourceRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                scope,
                diagnosticsResourceName,
                this.client.getApiVersion(),
                diagnosticResourceRequest,
                accept,
                context);
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DiagnosticResourceInner>, DiagnosticResourceInner> beginCreateAsync(
        String scope, String diagnosticsResourceName, DiagnosticResourceInner diagnosticResourceRequest) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(scope, diagnosticsResourceName, diagnosticResourceRequest);
        return this
            .client
            .<DiagnosticResourceInner, DiagnosticResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DiagnosticResourceInner.class,
                DiagnosticResourceInner.class,
                this.client.getContext());
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DiagnosticResourceInner>, DiagnosticResourceInner> beginCreateAsync(
        String scope, String diagnosticsResourceName) {
        final DiagnosticResourceInner diagnosticResourceRequest = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(scope, diagnosticsResourceName, diagnosticResourceRequest);
        return this
            .client
            .<DiagnosticResourceInner, DiagnosticResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DiagnosticResourceInner.class,
                DiagnosticResourceInner.class,
                this.client.getContext());
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DiagnosticResourceInner>, DiagnosticResourceInner> beginCreateAsync(
        String scope,
        String diagnosticsResourceName,
        DiagnosticResourceInner diagnosticResourceRequest,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(scope, diagnosticsResourceName, diagnosticResourceRequest, context);
        return this
            .client
            .<DiagnosticResourceInner, DiagnosticResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DiagnosticResourceInner.class,
                DiagnosticResourceInner.class,
                context);
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DiagnosticResourceInner>, DiagnosticResourceInner> beginCreate(
        String scope, String diagnosticsResourceName) {
        final DiagnosticResourceInner diagnosticResourceRequest = null;
        return this.beginCreateAsync(scope, diagnosticsResourceName, diagnosticResourceRequest).getSyncPoller();
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DiagnosticResourceInner>, DiagnosticResourceInner> beginCreate(
        String scope,
        String diagnosticsResourceName,
        DiagnosticResourceInner diagnosticResourceRequest,
        Context context) {
        return this
            .beginCreateAsync(scope, diagnosticsResourceName, diagnosticResourceRequest, context)
            .getSyncPoller();
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @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 diagnostic resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DiagnosticResourceInner> createAsync(
        String scope, String diagnosticsResourceName, DiagnosticResourceInner diagnosticResourceRequest) {
        return beginCreateAsync(scope, diagnosticsResourceName, diagnosticResourceRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostic resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DiagnosticResourceInner> createAsync(String scope, String diagnosticsResourceName) {
        final DiagnosticResourceInner diagnosticResourceRequest = null;
        return beginCreateAsync(scope, diagnosticsResourceName, diagnosticResourceRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @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 diagnostic resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DiagnosticResourceInner> createAsync(
        String scope,
        String diagnosticsResourceName,
        DiagnosticResourceInner diagnosticResourceRequest,
        Context context) {
        return beginCreateAsync(scope, diagnosticsResourceName, diagnosticResourceRequest, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DiagnosticResourceInner create(String scope, String diagnosticsResourceName) {
        final DiagnosticResourceInner diagnosticResourceRequest = null;
        return createAsync(scope, diagnosticsResourceName, diagnosticResourceRequest).block();
    }

    /**
     * Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once
     * you discover and identify the relevant solution for your Azure issue.&lt;br/&gt;&lt;br/&gt; You can create
     * diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’
     * &lt;br/&gt;&lt;br/&gt; &lt;b&gt;Note: &lt;/b&gt;‘requiredParameterSets’ from Solutions Discovery API response
     * must be passed via ‘additionalParameters’ as an input to Diagnostics API.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @param diagnosticResourceRequest The required request body for this insightResource invocation.
     * @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 diagnostic resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DiagnosticResourceInner create(
        String scope,
        String diagnosticsResourceName,
        DiagnosticResourceInner diagnosticResourceRequest,
        Context context) {
        return createAsync(scope, diagnosticsResourceName, diagnosticResourceRequest, context).block();
    }

    /**
     * Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DiagnosticResourceInner>> getWithResponseAsync(String scope, String diagnosticsResourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (diagnosticsResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter diagnosticsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            scope,
                            diagnosticsResourceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic along with
     *     {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DiagnosticResourceInner>> getWithResponseAsync(
        String scope, String diagnosticsResourceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (diagnosticsResourceName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter diagnosticsResourceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                scope,
                diagnosticsResourceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DiagnosticResourceInner> getAsync(String scope, String diagnosticsResourceName) {
        return getWithResponseAsync(scope, diagnosticsResourceName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic along with
     *     {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<DiagnosticResourceInner> getWithResponse(
        String scope, String diagnosticsResourceName, Context context) {
        return getWithResponseAsync(scope, diagnosticsResourceName, context).block();
    }

    /**
     * Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     *
     * @param scope This is an extension resource provider and only resource level extension is supported at the moment.
     * @param diagnosticsResourceName Unique resource name for insight resources.
     * @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 diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DiagnosticResourceInner get(String scope, String diagnosticsResourceName) {
        return getWithResponse(scope, diagnosticsResourceName, Context.NONE).getValue();
    }
}
