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

package com.azure.resourcemanager.authorization.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
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.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.authorization.fluent.ApplicationsClient;
import com.azure.resourcemanager.authorization.fluent.models.ApplicationInner;
import com.azure.resourcemanager.authorization.fluent.models.DirectoryObjectInner;
import com.azure.resourcemanager.authorization.fluent.models.KeyCredentialInner;
import com.azure.resourcemanager.authorization.fluent.models.PasswordCredentialInner;
import com.azure.resourcemanager.authorization.fluent.models.ServicePrincipalObjectResultInner;
import com.azure.resourcemanager.authorization.models.AddOwnerParameters;
import com.azure.resourcemanager.authorization.models.ApplicationCreateParameters;
import com.azure.resourcemanager.authorization.models.ApplicationListResult;
import com.azure.resourcemanager.authorization.models.ApplicationUpdateParameters;
import com.azure.resourcemanager.authorization.models.DirectoryObjectListResult;
import com.azure.resourcemanager.authorization.models.GraphErrorException;
import com.azure.resourcemanager.authorization.models.KeyCredentialListResult;
import com.azure.resourcemanager.authorization.models.KeyCredentialsUpdateParameters;
import com.azure.resourcemanager.authorization.models.PasswordCredentialListResult;
import com.azure.resourcemanager.authorization.models.PasswordCredentialsUpdateParameters;
import com.azure.resourcemanager.resources.fluentcore.collection.InnerSupportsDelete;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in ApplicationsClient. */
public final class ApplicationsClientImpl implements InnerSupportsDelete<Void>, ApplicationsClient {
    private final ClientLogger logger = new ClientLogger(ApplicationsClientImpl.class);

    /** The proxy service used to perform REST calls. */
    private final ApplicationsService service;

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

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

    /**
     * The interface defining all the services for GraphRbacManagementClientApplications to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "GraphRbacManagementC")
    private interface ApplicationsService {
        @Headers({"Content-Type: application/json"})
        @Post("/{tenantID}/applications")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<ApplicationInner>> create(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") ApplicationCreateParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/applications")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<ApplicationListResult>> list(
            @HostParam("$host") String endpoint,
            @QueryParam("$filter") String filter,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/{tenantID}/applications/{applicationObjectId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/applications/{applicationObjectId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<ApplicationInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/{tenantID}/applications/{applicationObjectId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> patch(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") ApplicationUpdateParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/applications/{applicationObjectId}/owners")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<DirectoryObjectListResult>> listOwners(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{tenantID}/applications/{applicationObjectId}/$links/owners")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> addOwner(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") AddOwnerParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/{tenantID}/applications/{applicationObjectId}/$links/owners/{ownerObjectId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> removeOwner(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @PathParam("ownerObjectId") String ownerObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/applications/{applicationObjectId}/keyCredentials")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<KeyCredentialListResult>> listKeyCredentials(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/{tenantID}/applications/{applicationObjectId}/keyCredentials")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> updateKeyCredentials(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") KeyCredentialsUpdateParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/applications/{applicationObjectId}/passwordCredentials")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<PasswordCredentialListResult>> listPasswordCredentials(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/{tenantID}/applications/{applicationObjectId}/passwordCredentials")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> updatePasswordCredentials(
            @HostParam("$host") String endpoint,
            @PathParam("applicationObjectId") String applicationObjectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") PasswordCredentialsUpdateParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/servicePrincipalsByAppId/{applicationID}/objectId")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<ServicePrincipalObjectResultInner>> getServicePrincipalsIdByAppId(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @PathParam("applicationID") String applicationId,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Create a new application.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for creating an application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return active Directory application information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<ApplicationInner>> createWithResponseAsync(
        String tenantId, ApplicationCreateParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a new application.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for creating an application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return active Directory application information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplicationInner>> createWithResponseAsync(
        String tenantId, ApplicationCreateParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .create(this.client.getEndpoint(), this.client.getApiVersion(), tenantId, parameters, accept, context);
    }

    /**
     * Create a new application.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for creating an application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return active Directory application information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ApplicationInner> createAsync(String tenantId, ApplicationCreateParameters parameters) {
        return createWithResponseAsync(tenantId, parameters)
            .flatMap(
                (Response<ApplicationInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Create a new application.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for creating an application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return active Directory application information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplicationInner create(String tenantId, ApplicationCreateParameters parameters) {
        return createAsync(tenantId, parameters).block();
    }

    /**
     * Create a new application.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for creating an application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return active Directory application information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplicationInner> createWithResponse(
        String tenantId, ApplicationCreateParameters parameters, Context context) {
        return createWithResponseAsync(tenantId, parameters, context).block();
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @param filter The filters to apply to the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplicationInner>> listSinglePageAsync(String tenantId, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(), filter, this.client.getApiVersion(), tenantId, accept, context))
            .<PagedResponse<ApplicationInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @param filter The filters to apply to the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplicationInner>> listSinglePageAsync(String tenantId, String filter, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), filter, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @param filter The filters to apply to the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<ApplicationInner> listAsync(String tenantId, String filter) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter), nextLink -> listNextSinglePageAsync(nextLink, tenantId));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<ApplicationInner> listAsync(String tenantId) {
        final String filter = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter), nextLink -> listNextSinglePageAsync(nextLink, tenantId));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @param filter The filters to apply to the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ApplicationInner> listAsync(String tenantId, String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter, context),
            nextLink -> listNextSinglePageAsync(nextLink, tenantId, context));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ApplicationInner> list(String tenantId) {
        final String filter = null;
        return new PagedIterable<>(listAsync(tenantId, filter));
    }

    /**
     * Lists applications by filter parameters.
     *
     * @param tenantId The tenant ID.
     * @param filter The filters to apply to the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return application list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ApplicationInner> list(String tenantId, String filter, Context context) {
        return new PagedIterable<>(listAsync(tenantId, filter, context));
    }

    /**
     * Delete an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteWithResponseAsync(String applicationObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String applicationObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(), applicationObjectId, this.client.getApiVersion(), tenantId, accept, context);
    }

    /**
     * Delete an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteAsync(String applicationObjectId, String tenantId) {
        return deleteWithResponseAsync(applicationObjectId, tenantId).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String applicationObjectId, String tenantId) {
        deleteAsync(applicationObjectId, tenantId).block();
    }

    /**
     * Delete an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String applicationObjectId, String tenantId, Context context) {
        return deleteWithResponseAsync(applicationObjectId, tenantId, context).block();
    }

    /**
     * Get an application by object ID.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an application by object ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<ApplicationInner>> getWithResponseAsync(String applicationObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get an application by object ID.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an application by object ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ApplicationInner>> getWithResponseAsync(
        String applicationObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(), applicationObjectId, this.client.getApiVersion(), tenantId, accept, context);
    }

    /**
     * Get an application by object ID.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an application by object ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ApplicationInner> getAsync(String applicationObjectId, String tenantId) {
        return getWithResponseAsync(applicationObjectId, tenantId)
            .flatMap(
                (Response<ApplicationInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Get an application by object ID.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an application by object ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ApplicationInner get(String applicationObjectId, String tenantId) {
        return getAsync(applicationObjectId, tenantId).block();
    }

    /**
     * Get an application by object ID.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an application by object ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ApplicationInner> getWithResponse(String applicationObjectId, String tenantId, Context context) {
        return getWithResponseAsync(applicationObjectId, tenantId, context).block();
    }

    /**
     * Update an existing application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> patchWithResponseAsync(
        String applicationObjectId, String tenantId, ApplicationUpdateParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .patch(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update an existing application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> patchWithResponseAsync(
        String applicationObjectId, String tenantId, ApplicationUpdateParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .patch(
                this.client.getEndpoint(),
                applicationObjectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Update an existing application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> patchAsync(String applicationObjectId, String tenantId, ApplicationUpdateParameters parameters) {
        return patchWithResponseAsync(applicationObjectId, tenantId, parameters)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Update an existing application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void patch(String applicationObjectId, String tenantId, ApplicationUpdateParameters parameters) {
        patchAsync(applicationObjectId, tenantId, parameters).block();
    }

    /**
     * Update an existing application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> patchWithResponse(
        String applicationObjectId, String tenantId, ApplicationUpdateParameters parameters, Context context) {
        return patchWithResponseAsync(applicationObjectId, tenantId, parameters, context).block();
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> listOwnersSinglePageAsync(
        String applicationObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listOwners(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .<PagedResponse<DirectoryObjectInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> listOwnersSinglePageAsync(
        String applicationObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .listOwners(
                this.client.getEndpoint(), applicationObjectId, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<DirectoryObjectInner> listOwnersAsync(String applicationObjectId, String tenantId) {
        return new PagedFlux<>(
            () -> listOwnersSinglePageAsync(applicationObjectId, tenantId),
            nextLink -> listOwnersNextSinglePageAsync(nextLink));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DirectoryObjectInner> listOwnersAsync(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedFlux<>(
            () -> listOwnersSinglePageAsync(applicationObjectId, tenantId, context),
            nextLink -> listOwnersNextSinglePageAsync(nextLink, context));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DirectoryObjectInner> listOwners(String applicationObjectId, String tenantId) {
        return new PagedIterable<>(listOwnersAsync(applicationObjectId, tenantId));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param applicationObjectId The object ID of the application for which to get owners.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DirectoryObjectInner> listOwners(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedIterable<>(listOwnersAsync(applicationObjectId, tenantId, context));
    }

    /**
     * Add an owner to an application.
     *
     * @param applicationObjectId The object ID of the application to which to add the owner.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the owner object, such as
     *     https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> addOwnerWithResponseAsync(
        String applicationObjectId, String tenantId, AddOwnerParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .addOwner(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Add an owner to an application.
     *
     * @param applicationObjectId The object ID of the application to which to add the owner.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the owner object, such as
     *     https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> addOwnerWithResponseAsync(
        String applicationObjectId, String tenantId, AddOwnerParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .addOwner(
                this.client.getEndpoint(),
                applicationObjectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Add an owner to an application.
     *
     * @param applicationObjectId The object ID of the application to which to add the owner.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the owner object, such as
     *     https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> addOwnerAsync(String applicationObjectId, String tenantId, AddOwnerParameters parameters) {
        return addOwnerWithResponseAsync(applicationObjectId, tenantId, parameters)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Add an owner to an application.
     *
     * @param applicationObjectId The object ID of the application to which to add the owner.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the owner object, such as
     *     https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void addOwner(String applicationObjectId, String tenantId, AddOwnerParameters parameters) {
        addOwnerAsync(applicationObjectId, tenantId, parameters).block();
    }

    /**
     * Add an owner to an application.
     *
     * @param applicationObjectId The object ID of the application to which to add the owner.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the owner object, such as
     *     https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> addOwnerWithResponse(
        String applicationObjectId, String tenantId, AddOwnerParameters parameters, Context context) {
        return addOwnerWithResponseAsync(applicationObjectId, tenantId, parameters, context).block();
    }

    /**
     * Remove a member from owners.
     *
     * @param applicationObjectId The object ID of the application from which to remove the owner.
     * @param ownerObjectId Owner object id.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> removeOwnerWithResponseAsync(
        String applicationObjectId, String ownerObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (ownerObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ownerObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .removeOwner(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            ownerObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Remove a member from owners.
     *
     * @param applicationObjectId The object ID of the application from which to remove the owner.
     * @param ownerObjectId Owner object id.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> removeOwnerWithResponseAsync(
        String applicationObjectId, String ownerObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (ownerObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter ownerObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .removeOwner(
                this.client.getEndpoint(),
                applicationObjectId,
                ownerObjectId,
                this.client.getApiVersion(),
                tenantId,
                accept,
                context);
    }

    /**
     * Remove a member from owners.
     *
     * @param applicationObjectId The object ID of the application from which to remove the owner.
     * @param ownerObjectId Owner object id.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> removeOwnerAsync(String applicationObjectId, String ownerObjectId, String tenantId) {
        return removeOwnerWithResponseAsync(applicationObjectId, ownerObjectId, tenantId)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Remove a member from owners.
     *
     * @param applicationObjectId The object ID of the application from which to remove the owner.
     * @param ownerObjectId Owner object id.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void removeOwner(String applicationObjectId, String ownerObjectId, String tenantId) {
        removeOwnerAsync(applicationObjectId, ownerObjectId, tenantId).block();
    }

    /**
     * Remove a member from owners.
     *
     * @param applicationObjectId The object ID of the application from which to remove the owner.
     * @param ownerObjectId Owner object id.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> removeOwnerWithResponse(
        String applicationObjectId, String ownerObjectId, String tenantId, Context context) {
        return removeOwnerWithResponseAsync(applicationObjectId, ownerObjectId, tenantId, context).block();
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<KeyCredentialInner>> listKeyCredentialsSinglePageAsync(
        String applicationObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listKeyCredentials(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .<PagedResponse<KeyCredentialInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<KeyCredentialInner>> listKeyCredentialsSinglePageAsync(
        String applicationObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .listKeyCredentials(
                this.client.getEndpoint(), applicationObjectId, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null));
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<KeyCredentialInner> listKeyCredentialsAsync(String applicationObjectId, String tenantId) {
        return new PagedFlux<>(() -> listKeyCredentialsSinglePageAsync(applicationObjectId, tenantId));
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<KeyCredentialInner> listKeyCredentialsAsync(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedFlux<>(() -> listKeyCredentialsSinglePageAsync(applicationObjectId, tenantId, context));
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<KeyCredentialInner> listKeyCredentials(String applicationObjectId, String tenantId) {
        return new PagedIterable<>(listKeyCredentialsAsync(applicationObjectId, tenantId));
    }

    /**
     * Get the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the keyCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<KeyCredentialInner> listKeyCredentials(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedIterable<>(listKeyCredentialsAsync(applicationObjectId, tenantId, context));
    }

    /**
     * Update the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update the keyCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> updateKeyCredentialsWithResponseAsync(
        String applicationObjectId, String tenantId, KeyCredentialsUpdateParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updateKeyCredentials(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update the keyCredentials of an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> updateKeyCredentialsWithResponseAsync(
        String applicationObjectId, String tenantId, KeyCredentialsUpdateParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .updateKeyCredentials(
                this.client.getEndpoint(),
                applicationObjectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Update the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update the keyCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> updateKeyCredentialsAsync(
        String applicationObjectId, String tenantId, KeyCredentialsUpdateParameters parameters) {
        return updateKeyCredentialsWithResponseAsync(applicationObjectId, tenantId, parameters)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Update the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update the keyCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void updateKeyCredentials(
        String applicationObjectId, String tenantId, KeyCredentialsUpdateParameters parameters) {
        updateKeyCredentialsAsync(applicationObjectId, tenantId, parameters).block();
    }

    /**
     * Update the keyCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update the keyCredentials of an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> updateKeyCredentialsWithResponse(
        String applicationObjectId, String tenantId, KeyCredentialsUpdateParameters parameters, Context context) {
        return updateKeyCredentialsWithResponseAsync(applicationObjectId, tenantId, parameters, context).block();
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PasswordCredentialInner>> listPasswordCredentialsSinglePageAsync(
        String applicationObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listPasswordCredentials(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .<PagedResponse<PasswordCredentialInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PasswordCredentialInner>> listPasswordCredentialsSinglePageAsync(
        String applicationObjectId, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .listPasswordCredentials(
                this.client.getEndpoint(), applicationObjectId, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null));
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<PasswordCredentialInner> listPasswordCredentialsAsync(
        String applicationObjectId, String tenantId) {
        return new PagedFlux<>(() -> listPasswordCredentialsSinglePageAsync(applicationObjectId, tenantId));
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PasswordCredentialInner> listPasswordCredentialsAsync(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedFlux<>(() -> listPasswordCredentialsSinglePageAsync(applicationObjectId, tenantId, context));
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PasswordCredentialInner> listPasswordCredentials(String applicationObjectId, String tenantId) {
        return new PagedIterable<>(listPasswordCredentialsAsync(applicationObjectId, tenantId));
    }

    /**
     * Get the passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the passwordCredentials associated with an application.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PasswordCredentialInner> listPasswordCredentials(
        String applicationObjectId, String tenantId, Context context) {
        return new PagedIterable<>(listPasswordCredentialsAsync(applicationObjectId, tenantId, context));
    }

    /**
     * Update passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update passwordCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> updatePasswordCredentialsWithResponseAsync(
        String applicationObjectId, String tenantId, PasswordCredentialsUpdateParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updatePasswordCredentials(
                            this.client.getEndpoint(),
                            applicationObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update passwordCredentials of an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> updatePasswordCredentialsWithResponseAsync(
        String applicationObjectId, String tenantId, PasswordCredentialsUpdateParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (applicationObjectId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .updatePasswordCredentials(
                this.client.getEndpoint(),
                applicationObjectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Update passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update passwordCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> updatePasswordCredentialsAsync(
        String applicationObjectId, String tenantId, PasswordCredentialsUpdateParameters parameters) {
        return updatePasswordCredentialsWithResponseAsync(applicationObjectId, tenantId, parameters)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Update passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update passwordCredentials of an existing application.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void updatePasswordCredentials(
        String applicationObjectId, String tenantId, PasswordCredentialsUpdateParameters parameters) {
        updatePasswordCredentialsAsync(applicationObjectId, tenantId, parameters).block();
    }

    /**
     * Update passwordCredentials associated with an application.
     *
     * @param applicationObjectId Application object ID.
     * @param tenantId The tenant ID.
     * @param parameters Parameters to update passwordCredentials of an existing application.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> updatePasswordCredentialsWithResponse(
        String applicationObjectId, String tenantId, PasswordCredentialsUpdateParameters parameters, Context context) {
        return updatePasswordCredentialsWithResponseAsync(applicationObjectId, tenantId, parameters, context).block();
    }

    /**
     * Gets an object id for a given application id from the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param applicationId The application ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an object id for a given application id from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<ServicePrincipalObjectResultInner>> getServicePrincipalsIdByAppIdWithResponseAsync(
        String tenantId, String applicationId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (applicationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter applicationId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getServicePrincipalsIdByAppId(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            tenantId,
                            applicationId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an object id for a given application id from the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param applicationId The application ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an object id for a given application id from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ServicePrincipalObjectResultInner>> getServicePrincipalsIdByAppIdWithResponseAsync(
        String tenantId, String applicationId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        if (applicationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter applicationId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .getServicePrincipalsIdByAppId(
                this.client.getEndpoint(), this.client.getApiVersion(), tenantId, applicationId, accept, context);
    }

    /**
     * Gets an object id for a given application id from the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param applicationId The application ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an object id for a given application id from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ServicePrincipalObjectResultInner> getServicePrincipalsIdByAppIdAsync(
        String tenantId, String applicationId) {
        return getServicePrincipalsIdByAppIdWithResponseAsync(tenantId, applicationId)
            .flatMap(
                (Response<ServicePrincipalObjectResultInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Gets an object id for a given application id from the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param applicationId The application ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an object id for a given application id from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ServicePrincipalObjectResultInner getServicePrincipalsIdByAppId(String tenantId, String applicationId) {
        return getServicePrincipalsIdByAppIdAsync(tenantId, applicationId).block();
    }

    /**
     * Gets an object id for a given application id from the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param applicationId The application ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an object id for a given application id from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ServicePrincipalObjectResultInner> getServicePrincipalsIdByAppIdWithResponse(
        String tenantId, String applicationId, Context context) {
        return getServicePrincipalsIdByAppIdWithResponseAsync(tenantId, applicationId, context).block();
    }

    /**
     * Gets a list of applications from the current tenant.
     *
     * @param nextLink Next link for the list operation.
     * @param tenantId The tenant ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of applications from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplicationInner>> listNextSinglePageAsync(String nextLink, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listNext(
                            this.client.getEndpoint(),
                            nextLink,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .<PagedResponse<ApplicationInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a list of applications from the current tenant.
     *
     * @param nextLink Next link for the list operation.
     * @param tenantId The tenant ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of applications from the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ApplicationInner>> listNextSinglePageAsync(
        String nextLink, String tenantId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (tenantId == null) {
            return Mono.error(new IllegalArgumentException("Parameter tenantId is required and cannot be null."));
        }
        final String accept = "application/json, text/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(this.client.getEndpoint(), nextLink, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> listOwnersNextSinglePageAsync(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, text/json";
        return FluxUtil
            .withContext(context -> service.listOwnersNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<DirectoryObjectInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws GraphErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return directoryObject list operation result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> listOwnersNextSinglePageAsync(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, text/json";
        context = this.client.mergeContext(context);
        return service
            .listOwnersNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }
}
