// 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.GitHubRepoesClient;
import com.azure.resourcemanager.securitydevops.fluent.models.GitHubRepoInner;
import com.azure.resourcemanager.securitydevops.models.GitHubRepoListResponse;
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 GitHubRepoesClient. */
public final class GitHubRepoesClientImpl implements GitHubRepoesClient {
    /** The proxy service used to perform REST calls. */
    private final GitHubRepoesService service;

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

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

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

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/gitHubConnectors/{gitHubConnectorName}/owners/{gitHubOwnerName}/repos")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<GitHubRepoListResponse>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("gitHubConnectorName") String gitHubConnectorName,
            @PathParam("gitHubOwnerName") String gitHubOwnerName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/gitHubConnectors/{gitHubConnectorName}/owners/{gitHubOwnerName}/repos/{gitHubRepoName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("gitHubConnectorName") String gitHubConnectorName,
            @PathParam("gitHubOwnerName") String gitHubOwnerName,
            @PathParam("gitHubRepoName") String gitHubRepoName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") GitHubRepoInner gitHubRepo,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityDevOps"
                + "/gitHubConnectors/{gitHubConnectorName}/owners/{gitHubOwnerName}/repos/{gitHubRepoName}")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("gitHubConnectorName") String gitHubConnectorName,
            @PathParam("gitHubOwnerName") String gitHubOwnerName,
            @PathParam("gitHubRepoName") String gitHubRepoName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") GitHubRepoInner gitHubRepo,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner>> listByConnectorSinglePageAsync(
        String resourceGroupName, String gitHubConnectorName) {
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByConnector(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            gitHubConnectorName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<GitHubRepoInner>>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()));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner>> listByConnectorSinglePageAsync(
        String resourceGroupName, String gitHubConnectorName, 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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByConnector(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                gitHubConnectorName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner> listByConnectorAsync(String resourceGroupName, String gitHubConnectorName) {
        return new PagedFlux<>(
            () -> listByConnectorSinglePageAsync(resourceGroupName, gitHubConnectorName),
            nextLink -> listByConnectorNextSinglePageAsync(nextLink));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner> listByConnectorAsync(
        String resourceGroupName, String gitHubConnectorName, Context context) {
        return new PagedFlux<>(
            () -> listByConnectorSinglePageAsync(resourceGroupName, gitHubConnectorName, context),
            nextLink -> listByConnectorNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner> listByConnector(String resourceGroupName, String gitHubConnectorName) {
        return new PagedIterable<>(listByConnectorAsync(resourceGroupName, gitHubConnectorName));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub 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<GitHubRepoInner> listByConnector(
        String resourceGroupName, String gitHubConnectorName, Context context) {
        return new PagedIterable<>(listByConnectorAsync(resourceGroupName, gitHubConnectorName, context));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner>> listSinglePageAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName) {
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            gitHubConnectorName,
                            gitHubOwnerName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<GitHubRepoInner>>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()));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner>> listSinglePageAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, 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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName 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,
                gitHubConnectorName,
                gitHubOwnerName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner> listAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner> listAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner> list(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName) {
        return new PagedIterable<>(listAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName));
    }

    /**
     * Returns a list of monitored GitHub repositories.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @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<GitHubRepoInner> list(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, context));
    }

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

    /**
     * Returns a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<GitHubRepoInner>> getWithResponseAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        if (gitHubRepoName == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepoName 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,
                gitHubConnectorName,
                gitHubOwnerName,
                gitHubRepoName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Returns a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> getAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        return getWithResponseAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Returns a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<GitHubRepoInner> getWithResponse(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        Context context) {
        return getWithResponseAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, context)
            .block();
    }

    /**
     * Returns a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GitHubRepoInner get(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        return getWithResponse(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, Context.NONE)
            .getValue();
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo 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 gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        if (gitHubRepoName == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepoName is required and cannot be null."));
        }
        if (gitHubRepo == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepo is required and cannot be null."));
        } else {
            gitHubRepo.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            gitHubConnectorName,
                            gitHubOwnerName,
                            gitHubRepoName,
                            this.client.getApiVersion(),
                            gitHubRepo,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo 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 gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        if (gitHubRepoName == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepoName is required and cannot be null."));
        }
        if (gitHubRepo == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepo is required and cannot be null."));
        } else {
            gitHubRepo.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                gitHubConnectorName,
                gitHubOwnerName,
                gitHubRepoName,
                this.client.getApiVersion(),
                gitHubRepo,
                accept,
                context);
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GitHubRepoInner>, GitHubRepoInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo);
        return this
            .client
            .<GitHubRepoInner, GitHubRepoInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                GitHubRepoInner.class,
                GitHubRepoInner.class,
                this.client.getContext());
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GitHubRepoInner>, GitHubRepoInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context);
        return this
            .client
            .<GitHubRepoInner, GitHubRepoInner>getLroResult(
                mono, this.client.getHttpPipeline(), GitHubRepoInner.class, GitHubRepoInner.class, context);
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GitHubRepoInner>, GitHubRepoInner> beginCreateOrUpdate(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .getSyncPoller();
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GitHubRepoInner>, GitHubRepoInner> beginCreateOrUpdate(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context)
            .getSyncPoller();
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> createOrUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> createOrUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GitHubRepoInner createOrUpdate(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        return createOrUpdateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .block();
    }

    /**
     * Create or update a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GitHubRepoInner createOrUpdate(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return createOrUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context)
            .block();
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo 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 gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        if (gitHubRepoName == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepoName is required and cannot be null."));
        }
        if (gitHubRepo != null) {
            gitHubRepo.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            gitHubConnectorName,
                            gitHubOwnerName,
                            gitHubRepoName,
                            this.client.getApiVersion(),
                            gitHubRepo,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo 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 gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        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 (gitHubConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubConnectorName is required and cannot be null."));
        }
        if (gitHubOwnerName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter gitHubOwnerName is required and cannot be null."));
        }
        if (gitHubRepoName == null) {
            return Mono.error(new IllegalArgumentException("Parameter gitHubRepoName is required and cannot be null."));
        }
        if (gitHubRepo != null) {
            gitHubRepo.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                gitHubConnectorName,
                gitHubOwnerName,
                gitHubRepoName,
                this.client.getApiVersion(),
                gitHubRepo,
                accept,
                context);
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GitHubRepoInner>, GitHubRepoInner> beginUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo);
        return this
            .client
            .<GitHubRepoInner, GitHubRepoInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                GitHubRepoInner.class,
                GitHubRepoInner.class,
                this.client.getContext());
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GitHubRepoInner>, GitHubRepoInner> beginUpdateAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        final GitHubRepoInner gitHubRepo = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo);
        return this
            .client
            .<GitHubRepoInner, GitHubRepoInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                GitHubRepoInner.class,
                GitHubRepoInner.class,
                this.client.getContext());
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GitHubRepoInner>, GitHubRepoInner> beginUpdateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context);
        return this
            .client
            .<GitHubRepoInner, GitHubRepoInner>getLroResult(
                mono, this.client.getHttpPipeline(), GitHubRepoInner.class, GitHubRepoInner.class, context);
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GitHubRepoInner>, GitHubRepoInner> beginUpdate(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        final GitHubRepoInner gitHubRepo = null;
        return beginUpdateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .getSyncPoller();
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GitHubRepoInner>, GitHubRepoInner> beginUpdate(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return beginUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context)
            .getSyncPoller();
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> updateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo) {
        return beginUpdateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> updateAsync(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        final GitHubRepoInner gitHubRepo = null;
        return beginUpdateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GitHubRepoInner> updateAsync(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return beginUpdateAsync(
                resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GitHubRepoInner update(
        String resourceGroupName, String gitHubConnectorName, String gitHubOwnerName, String gitHubRepoName) {
        final GitHubRepoInner gitHubRepo = null;
        return updateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo).block();
    }

    /**
     * Patch a monitored GitHub repository.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param gitHubConnectorName Name of the GitHub Connector.
     * @param gitHubOwnerName Name of the GitHub Owner.
     * @param gitHubRepoName Name of the GitHub Repo.
     * @param gitHubRepo Github repo.
     * @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 gitHub repo Proxy Resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GitHubRepoInner update(
        String resourceGroupName,
        String gitHubConnectorName,
        String gitHubOwnerName,
        String gitHubRepoName,
        GitHubRepoInner gitHubRepo,
        Context context) {
        return updateAsync(resourceGroupName, gitHubConnectorName, gitHubOwnerName, gitHubRepoName, gitHubRepo, 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<GitHubRepoInner>> listByConnectorNextSinglePageAsync(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.listByConnectorNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<GitHubRepoInner>>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<GitHubRepoInner>> listByConnectorNextSinglePageAsync(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
            .listByConnectorNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * 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<GitHubRepoInner>> 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<GitHubRepoInner>>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<GitHubRepoInner>> 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));
    }
}
