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

package com.azure.resourcemanager.securitydevops.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.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.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.securitydevops.fluent.AzureDevOpsOrgsClient;
import com.azure.resourcemanager.securitydevops.fluent.models.AzureDevOpsOrgInner;
import com.azure.resourcemanager.securitydevops.models.AzureDevOpsOrgListResponse;
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 AzureDevOpsOrgsClient. */
public final class AzureDevOpsOrgsClientImpl implements AzureDevOpsOrgsClient {
    /** The proxy service used to perform REST calls. */
    private final AzureDevOpsOrgsService service;

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

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

    /**
     * The interface defining all the services for MicrosoftSecurityDevOpsAzureDevOpsOrgs to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "MicrosoftSecurityDev")
    private interface AzureDevOpsOrgsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/azureDevOpsConnectors/{azureDevOpsConnectorName}/orgs")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<AzureDevOpsOrgListResponse>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("azureDevOpsConnectorName") String azureDevOpsConnectorName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/azureDevOpsConnectors/{azureDevOpsConnectorName}/orgs/{azureDevOpsOrgName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<AzureDevOpsOrgInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("azureDevOpsConnectorName") String azureDevOpsConnectorName,
            @PathParam("azureDevOpsOrgName") String azureDevOpsOrgName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/azureDevOpsConnectors/{azureDevOpsConnectorName}/orgs/{azureDevOpsOrgName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("azureDevOpsConnectorName") String azureDevOpsConnectorName,
            @PathParam("azureDevOpsOrgName") String azureDevOpsOrgName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") AzureDevOpsOrgInner azureDevOpsOrg,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/azureDevOpsConnectors/{azureDevOpsConnectorName}/orgs/{azureDevOpsOrgName}")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("azureDevOpsConnectorName") String azureDevOpsConnectorName,
            @PathParam("azureDevOpsOrgName") String azureDevOpsOrgName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") AzureDevOpsOrgInner azureDevOpsOrg,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AzureDevOpsOrgInner>> listSinglePageAsync(
        String resourceGroupName, String azureDevOpsConnectorName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            azureDevOpsConnectorName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<AzureDevOpsOrgInner>>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()));
    }

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AzureDevOpsOrgInner>> listSinglePageAsync(
        String resourceGroupName, String azureDevOpsConnectorName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                azureDevOpsConnectorName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AzureDevOpsOrgInner> listAsync(String resourceGroupName, String azureDevOpsConnectorName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, azureDevOpsConnectorName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AzureDevOpsOrgInner> listAsync(
        String resourceGroupName, String azureDevOpsConnectorName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, azureDevOpsConnectorName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AzureDevOpsOrgInner> list(String resourceGroupName, String azureDevOpsConnectorName) {
        return new PagedIterable<>(listAsync(resourceGroupName, azureDevOpsConnectorName));
    }

    /**
     * The list operation.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @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 paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AzureDevOpsOrgInner> list(
        String resourceGroupName, String azureDevOpsConnectorName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, azureDevOpsConnectorName, context));
    }

    /**
     * Returns a monitored AzureDevOps Org resource for a given ID.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureDevOpsOrgInner>> getWithResponseAsync(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            azureDevOpsConnectorName,
                            azureDevOpsOrgName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns a monitored AzureDevOps Org resource for a given ID.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureDevOpsOrgInner>> getWithResponseAsync(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                azureDevOpsConnectorName,
                azureDevOpsOrgName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Returns a monitored AzureDevOps Org resource for a given ID.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> getAsync(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        return getWithResponseAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Returns a monitored AzureDevOps Org resource for a given ID.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<AzureDevOpsOrgInner> getWithResponse(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName, Context context) {
        return getWithResponseAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, context).block();
    }

    /**
     * Returns a monitored AzureDevOps Org resource for a given ID.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureDevOpsOrgInner get(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        return getWithResponse(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, Context.NONE)
            .getValue();
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        if (azureDevOpsOrg == null) {
            return Mono.error(new IllegalArgumentException("Parameter azureDevOpsOrg is required and cannot be null."));
        } else {
            azureDevOpsOrg.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            azureDevOpsConnectorName,
                            azureDevOpsOrgName,
                            this.client.getApiVersion(),
                            azureDevOpsOrg,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        if (azureDevOpsOrg == null) {
            return Mono.error(new IllegalArgumentException("Parameter azureDevOpsOrg is required and cannot be null."));
        } else {
            azureDevOpsOrg.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                azureDevOpsConnectorName,
                azureDevOpsOrgName,
                this.client.getApiVersion(),
                azureDevOpsOrg,
                accept,
                context);
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg);
        return this
            .client
            .<AzureDevOpsOrgInner, AzureDevOpsOrgInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                AzureDevOpsOrgInner.class,
                AzureDevOpsOrgInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context);
        return this
            .client
            .<AzureDevOpsOrgInner, AzureDevOpsOrgInner>getLroResult(
                mono, this.client.getHttpPipeline(), AzureDevOpsOrgInner.class, AzureDevOpsOrgInner.class, context);
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginCreateOrUpdate(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        return beginCreateOrUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .getSyncPoller();
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginCreateOrUpdate(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .getSyncPoller();
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> createOrUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        return beginCreateOrUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> createOrUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureDevOpsOrgInner createOrUpdate(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        return createOrUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .block();
    }

    /**
     * Creates or updates an Azure DevOps Org.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureDevOpsOrgInner createOrUpdate(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return createOrUpdateAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .block();
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        if (azureDevOpsOrg != null) {
            azureDevOpsOrg.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            azureDevOpsConnectorName,
                            azureDevOpsOrgName,
                            this.client.getApiVersion(),
                            azureDevOpsOrg,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (azureDevOpsConnectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter azureDevOpsConnectorName is required and cannot be null."));
        }
        if (azureDevOpsOrgName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter azureDevOpsOrgName is required and cannot be null."));
        }
        if (azureDevOpsOrg != null) {
            azureDevOpsOrg.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                azureDevOpsConnectorName,
                azureDevOpsOrgName,
                this.client.getApiVersion(),
                azureDevOpsOrg,
                accept,
                context);
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg);
        return this
            .client
            .<AzureDevOpsOrgInner, AzureDevOpsOrgInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                AzureDevOpsOrgInner.class,
                AzureDevOpsOrgInner.class,
                this.client.getContext());
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginUpdateAsync(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        final AzureDevOpsOrgInner azureDevOpsOrg = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg);
        return this
            .client
            .<AzureDevOpsOrgInner, AzureDevOpsOrgInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                AzureDevOpsOrgInner.class,
                AzureDevOpsOrgInner.class,
                this.client.getContext());
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginUpdateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context);
        return this
            .client
            .<AzureDevOpsOrgInner, AzureDevOpsOrgInner>getLroResult(
                mono, this.client.getHttpPipeline(), AzureDevOpsOrgInner.class, AzureDevOpsOrgInner.class, context);
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginUpdate(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        final AzureDevOpsOrgInner azureDevOpsOrg = null;
        return beginUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .getSyncPoller();
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AzureDevOpsOrgInner>, AzureDevOpsOrgInner> beginUpdate(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return beginUpdateAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .getSyncPoller();
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> updateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg) {
        return beginUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> updateAsync(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        final AzureDevOpsOrgInner azureDevOpsOrg = null;
        return beginUpdateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureDevOpsOrgInner> updateAsync(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return beginUpdateAsync(
                resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureDevOpsOrgInner update(
        String resourceGroupName, String azureDevOpsConnectorName, String azureDevOpsOrgName) {
        final AzureDevOpsOrgInner azureDevOpsOrg = null;
        return updateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg).block();
    }

    /**
     * Update monitored AzureDevOps Org details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param azureDevOpsConnectorName Name of the AzureDevOps Connector.
     * @param azureDevOpsOrgName Name of the AzureDevOps Org.
     * @param azureDevOpsOrg Azure DevOps Org resource payload.
     * @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 azure DevOps Org Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureDevOpsOrgInner update(
        String resourceGroupName,
        String azureDevOpsConnectorName,
        String azureDevOpsOrgName,
        AzureDevOpsOrgInner azureDevOpsOrg,
        Context context) {
        return updateAsync(resourceGroupName, azureDevOpsConnectorName, azureDevOpsOrgName, azureDevOpsOrg, context)
            .block();
    }

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