// 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.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.GroupsClient;
import com.azure.resourcemanager.authorization.fluent.models.ADGroupInner;
import com.azure.resourcemanager.authorization.fluent.models.CheckGroupMembershipResultInner;
import com.azure.resourcemanager.authorization.fluent.models.DirectoryObjectInner;
import com.azure.resourcemanager.authorization.models.AddOwnerParameters;
import com.azure.resourcemanager.authorization.models.CheckGroupMembershipParameters;
import com.azure.resourcemanager.authorization.models.DirectoryObjectListResult;
import com.azure.resourcemanager.authorization.models.GraphErrorException;
import com.azure.resourcemanager.authorization.models.GroupAddMemberParameters;
import com.azure.resourcemanager.authorization.models.GroupCreateParameters;
import com.azure.resourcemanager.authorization.models.GroupGetMemberGroupsParameters;
import com.azure.resourcemanager.authorization.models.GroupGetMemberGroupsResult;
import com.azure.resourcemanager.authorization.models.GroupListResult;
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 GroupsClient. */
public final class GroupsClientImpl implements InnerSupportsDelete<Void>, GroupsClient {
    private final ClientLogger logger = new ClientLogger(GroupsClientImpl.class);

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

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post("/{tenantID}/groups")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<ADGroupInner>> create(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") GroupCreateParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{tenantID}/groups")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<GroupListResult>> 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"})
        @Get("/{tenantID}/groups/{objectId}/members")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<DirectoryObjectListResult>> getGroupMembers(
            @HostParam("$host") String endpoint,
            @PathParam("objectId") String objectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Post("/{tenantID}/groups/{objectId}/getMemberGroups")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<GroupGetMemberGroupsResult>> getMemberGroups(
            @HostParam("$host") String endpoint,
            @PathParam("objectId") String objectId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("tenantID") String tenantId,
            @BodyParam("application/json") GroupGetMemberGroupsParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post("/{tenantID}/groups/{objectId}/$links/owners")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> addOwner(
            @HostParam("$host") String endpoint,
            @PathParam("objectId") String objectId,
            @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}/groups/{objectId}/$links/owners/{ownerObjectId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<Void>> removeOwner(
            @HostParam("$host") String endpoint,
            @PathParam("objectId") String objectId,
            @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}/{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<GroupListResult>> 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("/{tenantID}/{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(GraphErrorException.class)
        Mono<Response<DirectoryObjectListResult>> getGroupMembersNext(
            @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);
    }

    /**
     * Checks whether the specified user, group, contact, or service principal is a direct or transitive member of the
     * specified group.
     *
     * @param tenantId The tenant ID.
     * @param parameters The check group membership parameters.
     * @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 server response for IsMemberOf API call.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CheckGroupMembershipResultInner>> isMemberOfWithResponseAsync(
        String tenantId, CheckGroupMembershipParameters 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
                        .isMemberOf(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Checks whether the specified user, group, contact, or service principal is a direct or transitive member of the
     * specified group.
     *
     * @param tenantId The tenant ID.
     * @param parameters The check group membership parameters.
     * @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 server response for IsMemberOf API call.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckGroupMembershipResultInner>> isMemberOfWithResponseAsync(
        String tenantId, CheckGroupMembershipParameters 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
            .isMemberOf(this.client.getEndpoint(), this.client.getApiVersion(), tenantId, parameters, accept, context);
    }

    /**
     * Checks whether the specified user, group, contact, or service principal is a direct or transitive member of the
     * specified group.
     *
     * @param tenantId The tenant ID.
     * @param parameters The check group membership parameters.
     * @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 server response for IsMemberOf API call.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CheckGroupMembershipResultInner> isMemberOfAsync(
        String tenantId, CheckGroupMembershipParameters parameters) {
        return isMemberOfWithResponseAsync(tenantId, parameters)
            .flatMap(
                (Response<CheckGroupMembershipResultInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Checks whether the specified user, group, contact, or service principal is a direct or transitive member of the
     * specified group.
     *
     * @param tenantId The tenant ID.
     * @param parameters The check group membership parameters.
     * @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 server response for IsMemberOf API call.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckGroupMembershipResultInner isMemberOf(String tenantId, CheckGroupMembershipParameters parameters) {
        return isMemberOfAsync(tenantId, parameters).block();
    }

    /**
     * Checks whether the specified user, group, contact, or service principal is a direct or transitive member of the
     * specified group.
     *
     * @param tenantId The tenant ID.
     * @param parameters The check group membership parameters.
     * @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 server response for IsMemberOf API call.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckGroupMembershipResultInner> isMemberOfWithResponse(
        String tenantId, CheckGroupMembershipParameters parameters, Context context) {
        return isMemberOfWithResponseAsync(tenantId, parameters, context).block();
    }

    /**
     * Remove a member from a group.
     *
     * @param groupObjectId The object ID of the group from which to remove the member.
     * @param memberObjectId Member 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>> removeMemberWithResponseAsync(
        String groupObjectId, String memberObjectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."));
        }
        if (memberObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter memberObjectId 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
                        .removeMember(
                            this.client.getEndpoint(),
                            groupObjectId,
                            memberObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Remove a member from a group.
     *
     * @param groupObjectId The object ID of the group from which to remove the member.
     * @param memberObjectId Member 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>> removeMemberWithResponseAsync(
        String groupObjectId, String memberObjectId, 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 (groupObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."));
        }
        if (memberObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter memberObjectId 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
            .removeMember(
                this.client.getEndpoint(),
                groupObjectId,
                memberObjectId,
                this.client.getApiVersion(),
                tenantId,
                accept,
                context);
    }

    /**
     * Remove a member from a group.
     *
     * @param groupObjectId The object ID of the group from which to remove the member.
     * @param memberObjectId Member 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> removeMemberAsync(String groupObjectId, String memberObjectId, String tenantId) {
        return removeMemberWithResponseAsync(groupObjectId, memberObjectId, tenantId)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Remove a member from a group.
     *
     * @param groupObjectId The object ID of the group from which to remove the member.
     * @param memberObjectId Member 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 removeMember(String groupObjectId, String memberObjectId, String tenantId) {
        removeMemberAsync(groupObjectId, memberObjectId, tenantId).block();
    }

    /**
     * Remove a member from a group.
     *
     * @param groupObjectId The object ID of the group from which to remove the member.
     * @param memberObjectId Member 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> removeMemberWithResponse(
        String groupObjectId, String memberObjectId, String tenantId, Context context) {
        return removeMemberWithResponseAsync(groupObjectId, memberObjectId, tenantId, context).block();
    }

    /**
     * Add a member to a group.
     *
     * @param groupObjectId The object ID of the group to which to add the member.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the member 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>> addMemberWithResponseAsync(
        String groupObjectId, String tenantId, GroupAddMemberParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupObjectId 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
                        .addMember(
                            this.client.getEndpoint(),
                            groupObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Add a member to a group.
     *
     * @param groupObjectId The object ID of the group to which to add the member.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the member 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>> addMemberWithResponseAsync(
        String groupObjectId, String tenantId, GroupAddMemberParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (groupObjectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupObjectId 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
            .addMember(
                this.client.getEndpoint(),
                groupObjectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Add a member to a group.
     *
     * @param groupObjectId The object ID of the group to which to add the member.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the member 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> addMemberAsync(String groupObjectId, String tenantId, GroupAddMemberParameters parameters) {
        return addMemberWithResponseAsync(groupObjectId, tenantId, parameters)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Add a member to a group.
     *
     * @param groupObjectId The object ID of the group to which to add the member.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the member 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 addMember(String groupObjectId, String tenantId, GroupAddMemberParameters parameters) {
        addMemberAsync(groupObjectId, tenantId, parameters).block();
    }

    /**
     * Add a member to a group.
     *
     * @param groupObjectId The object ID of the group to which to add the member.
     * @param tenantId The tenant ID.
     * @param parameters The URL of the member 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> addMemberWithResponse(
        String groupObjectId, String tenantId, GroupAddMemberParameters parameters, Context context) {
        return addMemberWithResponseAsync(groupObjectId, tenantId, parameters, context).block();
    }

    /**
     * Create a group in the directory.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for the group to create.
     * @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 group information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<ADGroupInner>> createWithResponseAsync(String tenantId, GroupCreateParameters 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 group in the directory.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for the group to create.
     * @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 group information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ADGroupInner>> createWithResponseAsync(
        String tenantId, GroupCreateParameters 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 group in the directory.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for the group to create.
     * @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 group information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ADGroupInner> createAsync(String tenantId, GroupCreateParameters parameters) {
        return createWithResponseAsync(tenantId, parameters)
            .flatMap(
                (Response<ADGroupInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Create a group in the directory.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for the group to create.
     * @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 group information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ADGroupInner create(String tenantId, GroupCreateParameters parameters) {
        return createAsync(tenantId, parameters).block();
    }

    /**
     * Create a group in the directory.
     *
     * @param tenantId The tenant ID.
     * @param parameters The parameters for the group to create.
     * @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 group information.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ADGroupInner> createWithResponse(
        String tenantId, GroupCreateParameters parameters, Context context) {
        return createWithResponseAsync(tenantId, parameters, context).block();
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param filter The filter 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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ADGroupInner>> 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<ADGroupInner>>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 list of groups for the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param filter The filter 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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ADGroupInner>> 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));
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param filter The filter 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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<ADGroupInner> listAsync(String tenantId, String filter) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter), nextLink -> listNextSinglePageAsync(nextLink, tenantId));
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<ADGroupInner> listAsync(String tenantId) {
        final String filter = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter), nextLink -> listNextSinglePageAsync(nextLink, tenantId));
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param filter The filter 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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ADGroupInner> listAsync(String tenantId, String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(tenantId, filter, context),
            nextLink -> listNextSinglePageAsync(nextLink, tenantId, context));
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ADGroupInner> list(String tenantId) {
        final String filter = null;
        return new PagedIterable<>(listAsync(tenantId, filter));
    }

    /**
     * Gets list of groups for the current tenant.
     *
     * @param tenantId The tenant ID.
     * @param filter The filter 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 list of groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ADGroupInner> list(String tenantId, String filter, Context context) {
        return new PagedIterable<>(listAsync(tenantId, filter, context));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> getGroupMembersSinglePageAsync(String objectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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
                        .getGroupMembers(
                            this.client.getEndpoint(),
                            objectId,
                            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()));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> getGroupMembersSinglePageAsync(
        String objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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
            .getGroupMembers(
                this.client.getEndpoint(), objectId, this.client.getApiVersion(), tenantId, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<DirectoryObjectInner> getGroupMembersAsync(String objectId, String tenantId) {
        return new PagedFlux<>(
            () -> getGroupMembersSinglePageAsync(objectId, tenantId),
            nextLink -> getGroupMembersNextSinglePageAsync(nextLink, tenantId));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DirectoryObjectInner> getGroupMembersAsync(String objectId, String tenantId, Context context) {
        return new PagedFlux<>(
            () -> getGroupMembersSinglePageAsync(objectId, tenantId, context),
            nextLink -> getGroupMembersNextSinglePageAsync(nextLink, tenantId, context));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DirectoryObjectInner> getGroupMembers(String objectId, String tenantId) {
        return new PagedIterable<>(getGroupMembersAsync(objectId, tenantId));
    }

    /**
     * Gets the members of a group.
     *
     * @param objectId The object ID of the group whose members should be retrieved.
     * @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 members of a group.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DirectoryObjectInner> getGroupMembers(String objectId, String tenantId, Context context) {
        return new PagedIterable<>(getGroupMembersAsync(objectId, tenantId, context));
    }

    /**
     * Gets group information from the directory.
     *
     * @param objectId The object ID of the user for which to get group information.
     * @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 group information from the directory.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<ADGroupInner>> getWithResponseAsync(String objectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                            objectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets group information from the directory.
     *
     * @param objectId The object ID of the user for which to get group information.
     * @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 group information from the directory.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ADGroupInner>> getWithResponseAsync(String objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(), objectId, this.client.getApiVersion(), tenantId, accept, context);
    }

    /**
     * Gets group information from the directory.
     *
     * @param objectId The object ID of the user for which to get group information.
     * @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 group information from the directory.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ADGroupInner> getAsync(String objectId, String tenantId) {
        return getWithResponseAsync(objectId, tenantId)
            .flatMap(
                (Response<ADGroupInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Gets group information from the directory.
     *
     * @param objectId The object ID of the user for which to get group information.
     * @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 group information from the directory.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ADGroupInner get(String objectId, String tenantId) {
        return getAsync(objectId, tenantId).block();
    }

    /**
     * Gets group information from the directory.
     *
     * @param objectId The object ID of the user for which to get group information.
     * @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 group information from the directory.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ADGroupInner> getWithResponse(String objectId, String tenantId, Context context) {
        return getWithResponseAsync(objectId, tenantId, context).block();
    }

    /**
     * Delete a group from the directory.
     *
     * @param objectId The object ID of the group to delete.
     * @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 objectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                            objectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a group from the directory.
     *
     * @param objectId The object ID of the group to delete.
     * @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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(), objectId, this.client.getApiVersion(), tenantId, accept, context);
    }

    /**
     * Delete a group from the directory.
     *
     * @param objectId The object ID of the group to delete.
     * @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 objectId, String tenantId) {
        return deleteWithResponseAsync(objectId, tenantId).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete a group from the directory.
     *
     * @param objectId The object ID of the group to delete.
     * @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 objectId, String tenantId) {
        deleteAsync(objectId, tenantId).block();
    }

    /**
     * Delete a group from the directory.
     *
     * @param objectId The object ID of the group to delete.
     * @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 objectId, String tenantId, Context context) {
        return deleteWithResponseAsync(objectId, tenantId, context).block();
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<String>> getMemberGroupsSinglePageAsync(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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
                        .getMemberGroups(
                            this.client.getEndpoint(),
                            objectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .<PagedResponse<String>>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()));
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<String>> getMemberGroupsSinglePageAsync(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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
            .getMemberGroups(
                this.client.getEndpoint(), objectId, this.client.getApiVersion(), tenantId, parameters, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().value(), null, null));
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<String> getMemberGroupsAsync(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters) {
        return new PagedFlux<>(() -> getMemberGroupsSinglePageAsync(objectId, tenantId, parameters));
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<String> getMemberGroupsAsync(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters, Context context) {
        return new PagedFlux<>(() -> getMemberGroupsSinglePageAsync(objectId, tenantId, parameters, context));
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<String> getMemberGroups(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters) {
        return new PagedIterable<>(getMemberGroupsAsync(objectId, tenantId, parameters));
    }

    /**
     * Gets a collection of object IDs of groups of which the specified group is a member.
     *
     * @param objectId The object ID of the group for which to get group membership.
     * @param tenantId The tenant ID.
     * @param parameters Group filtering parameters.
     * @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 collection of object IDs of groups of which the specified group is a member.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<String> getMemberGroups(
        String objectId, String tenantId, GroupGetMemberGroupsParameters parameters, Context context) {
        return new PagedIterable<>(getMemberGroupsAsync(objectId, tenantId, parameters, context));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param objectId The object ID of the group 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 objectId, String tenantId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                            objectId,
                            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 objectId The object ID of the group 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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(), objectId, 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 objectId The object ID of the group 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 objectId, String tenantId) {
        return new PagedFlux<>(
            () -> listOwnersSinglePageAsync(objectId, tenantId), nextLink -> listOwnersNextSinglePageAsync(nextLink));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param objectId The object ID of the group 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 objectId, String tenantId, Context context) {
        return new PagedFlux<>(
            () -> listOwnersSinglePageAsync(objectId, tenantId, context),
            nextLink -> listOwnersNextSinglePageAsync(nextLink, context));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param objectId The object ID of the group 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 objectId, String tenantId) {
        return new PagedIterable<>(listOwnersAsync(objectId, tenantId));
    }

    /**
     * The owners are a set of non-admin users who are allowed to modify this object.
     *
     * @param objectId The object ID of the group 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 objectId, String tenantId, Context context) {
        return new PagedIterable<>(listOwnersAsync(objectId, tenantId, context));
    }

    /**
     * Add an owner to a group.
     *
     * @param objectId 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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                            objectId,
                            this.client.getApiVersion(),
                            tenantId,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Add an owner to a group.
     *
     * @param objectId 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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                objectId,
                this.client.getApiVersion(),
                tenantId,
                parameters,
                accept,
                context);
    }

    /**
     * Add an owner to a group.
     *
     * @param objectId 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 objectId, String tenantId, AddOwnerParameters parameters) {
        return addOwnerWithResponseAsync(objectId, tenantId, parameters).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Add an owner to a group.
     *
     * @param objectId 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 objectId, String tenantId, AddOwnerParameters parameters) {
        addOwnerAsync(objectId, tenantId, parameters).block();
    }

    /**
     * Add an owner to a group.
     *
     * @param objectId 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 objectId, String tenantId, AddOwnerParameters parameters, Context context) {
        return addOwnerWithResponseAsync(objectId, tenantId, parameters, context).block();
    }

    /**
     * Remove a member from owners.
     *
     * @param objectId The object ID of the group 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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                            objectId,
                            ownerObjectId,
                            this.client.getApiVersion(),
                            tenantId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Remove a member from owners.
     *
     * @param objectId The object ID of the group 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 objectId, 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 (objectId == null) {
            return Mono.error(new IllegalArgumentException("Parameter objectId 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(),
                objectId,
                ownerObjectId,
                this.client.getApiVersion(),
                tenantId,
                accept,
                context);
    }

    /**
     * Remove a member from owners.
     *
     * @param objectId The object ID of the group 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 objectId, String ownerObjectId, String tenantId) {
        return removeOwnerWithResponseAsync(objectId, ownerObjectId, tenantId)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Remove a member from owners.
     *
     * @param objectId The object ID of the group 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 objectId, String ownerObjectId, String tenantId) {
        removeOwnerAsync(objectId, ownerObjectId, tenantId).block();
    }

    /**
     * Remove a member from owners.
     *
     * @param objectId The object ID of the group 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 objectId, String ownerObjectId, String tenantId, Context context) {
        return removeOwnerWithResponseAsync(objectId, ownerObjectId, tenantId, context).block();
    }

    /**
     * Gets a list of groups for 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 groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ADGroupInner>> 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<ADGroupInner>>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 groups for 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 groups for the current tenant.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ADGroupInner>> 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));
    }

    /**
     * Gets the members of a group.
     *
     * @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 the members of a group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> getGroupMembersNextSinglePageAsync(
        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
                        .getGroupMembersNext(
                            this.client.getEndpoint(),
                            nextLink,
                            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()));
    }

    /**
     * Gets the members of a group.
     *
     * @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 the members of a group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DirectoryObjectInner>> getGroupMembersNextSinglePageAsync(
        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
            .getGroupMembersNext(
                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));
    }
}
