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

package com.azure.analytics.synapse.accesscontrol.implementation;

import com.azure.analytics.synapse.accesscontrol.models.CheckPrincipalAccessRequest;
import com.azure.analytics.synapse.accesscontrol.models.CheckPrincipalAccessResponse;
import com.azure.analytics.synapse.accesscontrol.models.ErrorContractException;
import com.azure.analytics.synapse.accesscontrol.models.RequiredAction;
import com.azure.analytics.synapse.accesscontrol.models.RoleAssignmentDetails;
import com.azure.analytics.synapse.accesscontrol.models.RoleAssignmentDetailsList;
import com.azure.analytics.synapse.accesscontrol.models.RoleAssignmentRequest;
import com.azure.analytics.synapse.accesscontrol.models.RoleAssignmentsListRoleAssignmentsResponse;
import com.azure.analytics.synapse.accesscontrol.models.SubjectInfo;
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.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import java.util.List;
import java.util.UUID;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AccessControlClientRoleAssignments to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "AccessControlClientR")
    public interface RoleAssignmentsService {
        @Post("/checkAccessSynapseRbac")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<CheckPrincipalAccessResponse>> checkPrincipalAccess(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") CheckPrincipalAccessRequest request,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/roleAssignments")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<RoleAssignmentsListRoleAssignmentsResponse> listRoleAssignments(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @QueryParam("roleId") String roleId,
                @QueryParam("principalId") String principalId,
                @QueryParam("scope") String scope,
                @HeaderParam("x-ms-continuation") String continuationToken,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/roleAssignments/{roleAssignmentId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<RoleAssignmentDetails>> createRoleAssignment(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("roleAssignmentId") String roleAssignmentId,
                @BodyParam("application/json") RoleAssignmentRequest request,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/roleAssignments/{roleAssignmentId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<RoleAssignmentDetails>> getRoleAssignmentById(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("roleAssignmentId") String roleAssignmentId,
                @HeaderParam("Accept") String accept,
                Context context);

        @Delete("/roleAssignments/{roleAssignmentId}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<Void>> deleteRoleAssignmentById(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("roleAssignmentId") String roleAssignmentId,
                @QueryParam("scope") String scope,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CheckPrincipalAccessResponse>> checkPrincipalAccessWithResponseAsync(
            SubjectInfo subject, List<RequiredAction> actions, String scope) {
        final String accept = "application/json, text/json";
        CheckPrincipalAccessRequest request = new CheckPrincipalAccessRequest();
        request.setSubject(subject);
        request.setActions(actions);
        request.setScope(scope);
        return FluxUtil.withContext(
                context ->
                        service.checkPrincipalAccess(
                                this.client.getEndpoint(), this.client.getApiVersion(), request, accept, context));
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CheckPrincipalAccessResponse>> checkPrincipalAccessWithResponseAsync(
            SubjectInfo subject, List<RequiredAction> actions, String scope, Context context) {
        final String accept = "application/json, text/json";
        CheckPrincipalAccessRequest request = new CheckPrincipalAccessRequest();
        request.setSubject(subject);
        request.setActions(actions);
        request.setScope(scope);
        return service.checkPrincipalAccess(
                this.client.getEndpoint(), this.client.getApiVersion(), request, accept, context);
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CheckPrincipalAccessResponse> checkPrincipalAccessAsync(
            SubjectInfo subject, List<RequiredAction> actions, String scope) {
        return checkPrincipalAccessWithResponseAsync(subject, actions, scope)
                .flatMap(
                        (Response<CheckPrincipalAccessResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CheckPrincipalAccessResponse> checkPrincipalAccessAsync(
            SubjectInfo subject, List<RequiredAction> actions, String scope, Context context) {
        return checkPrincipalAccessWithResponseAsync(subject, actions, scope, context)
                .flatMap(
                        (Response<CheckPrincipalAccessResponse> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckPrincipalAccessResponse checkPrincipalAccess(
            SubjectInfo subject, List<RequiredAction> actions, String scope) {
        return checkPrincipalAccessAsync(subject, actions, scope).block();
    }

    /**
     * Check if the given principalId has access to perform list of actions at a given scope.
     *
     * @param subject Subject details.
     * @param actions List of actions.
     * @param scope Scope at which the check access is done.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return check access response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckPrincipalAccessResponse> checkPrincipalAccessWithResponse(
            SubjectInfo subject, List<RequiredAction> actions, String scope, Context context) {
        return checkPrincipalAccessWithResponseAsync(subject, actions, scope, context).block();
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentsListRoleAssignmentsResponse> listRoleAssignmentsWithResponseAsync(
            String roleId, String principalId, String scope, String continuationToken) {
        final String accept = "application/json, text/json";
        return FluxUtil.withContext(
                context ->
                        service.listRoleAssignments(
                                this.client.getEndpoint(),
                                this.client.getApiVersion(),
                                roleId,
                                principalId,
                                scope,
                                continuationToken,
                                accept,
                                context));
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentsListRoleAssignmentsResponse> listRoleAssignmentsWithResponseAsync(
            String roleId, String principalId, String scope, String continuationToken, Context context) {
        final String accept = "application/json, text/json";
        return service.listRoleAssignments(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                roleId,
                principalId,
                scope,
                continuationToken,
                accept,
                context);
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetailsList> listRoleAssignmentsAsync(
            String roleId, String principalId, String scope, String continuationToken) {
        return listRoleAssignmentsWithResponseAsync(roleId, principalId, scope, continuationToken)
                .flatMap(
                        (RoleAssignmentsListRoleAssignmentsResponse res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * List role assignments.
     *
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetailsList> listRoleAssignmentsAsync() {
        final String roleId = null;
        final String principalId = null;
        final String scope = null;
        final String continuationToken = null;
        return listRoleAssignmentsWithResponseAsync(roleId, principalId, scope, continuationToken)
                .flatMap(
                        (RoleAssignmentsListRoleAssignmentsResponse res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetailsList> listRoleAssignmentsAsync(
            String roleId, String principalId, String scope, String continuationToken, Context context) {
        return listRoleAssignmentsWithResponseAsync(roleId, principalId, scope, continuationToken, context)
                .flatMap(
                        (RoleAssignmentsListRoleAssignmentsResponse res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentDetailsList listRoleAssignments(
            String roleId, String principalId, String scope, String continuationToken) {
        return listRoleAssignmentsAsync(roleId, principalId, scope, continuationToken).block();
    }

    /**
     * List role assignments.
     *
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentDetailsList listRoleAssignments() {
        final String roleId = null;
        final String principalId = null;
        final String scope = null;
        final String continuationToken = null;
        return listRoleAssignmentsAsync(roleId, principalId, scope, continuationToken).block();
    }

    /**
     * List role assignments.
     *
     * @param roleId Synapse Built-In Role Id.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope of the Synapse Built-in Role.
     * @param continuationToken Continuation token.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentsListRoleAssignmentsResponse listRoleAssignmentsWithResponse(
            String roleId, String principalId, String scope, String continuationToken, Context context) {
        return listRoleAssignmentsWithResponseAsync(roleId, principalId, scope, continuationToken, context).block();
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<RoleAssignmentDetails>> createRoleAssignmentWithResponseAsync(
            String roleAssignmentId, UUID roleId, UUID principalId, String scope, String principalType) {
        final String accept = "application/json, text/json";
        RoleAssignmentRequest request = new RoleAssignmentRequest();
        request.setRoleId(roleId);
        request.setPrincipalId(principalId);
        request.setScope(scope);
        request.setPrincipalType(principalType);
        return FluxUtil.withContext(
                context ->
                        service.createRoleAssignment(
                                this.client.getEndpoint(),
                                this.client.getApiVersion(),
                                roleAssignmentId,
                                request,
                                accept,
                                context));
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<RoleAssignmentDetails>> createRoleAssignmentWithResponseAsync(
            String roleAssignmentId,
            UUID roleId,
            UUID principalId,
            String scope,
            String principalType,
            Context context) {
        final String accept = "application/json, text/json";
        RoleAssignmentRequest request = new RoleAssignmentRequest();
        request.setRoleId(roleId);
        request.setPrincipalId(principalId);
        request.setScope(scope);
        request.setPrincipalType(principalType);
        return service.createRoleAssignment(
                this.client.getEndpoint(), this.client.getApiVersion(), roleAssignmentId, request, accept, context);
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetails> createRoleAssignmentAsync(
            String roleAssignmentId, UUID roleId, UUID principalId, String scope, String principalType) {
        return createRoleAssignmentWithResponseAsync(roleAssignmentId, roleId, principalId, scope, principalType)
                .flatMap(
                        (Response<RoleAssignmentDetails> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetails> createRoleAssignmentAsync(
            String roleAssignmentId, UUID roleId, UUID principalId, String scope) {
        final String principalType = null;
        return createRoleAssignmentWithResponseAsync(roleAssignmentId, roleId, principalId, scope, principalType)
                .flatMap(
                        (Response<RoleAssignmentDetails> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetails> createRoleAssignmentAsync(
            String roleAssignmentId,
            UUID roleId,
            UUID principalId,
            String scope,
            String principalType,
            Context context) {
        return createRoleAssignmentWithResponseAsync(
                        roleAssignmentId, roleId, principalId, scope, principalType, context)
                .flatMap(
                        (Response<RoleAssignmentDetails> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentDetails createRoleAssignment(
            String roleAssignmentId, UUID roleId, UUID principalId, String scope, String principalType) {
        return createRoleAssignmentAsync(roleAssignmentId, roleId, principalId, scope, principalType).block();
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentDetails createRoleAssignment(
            String roleAssignmentId, UUID roleId, UUID principalId, String scope) {
        final String principalType = null;
        return createRoleAssignmentAsync(roleAssignmentId, roleId, principalId, scope, principalType).block();
    }

    /**
     * Create role assignment.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param roleId Role ID of the Synapse Built-In Role.
     * @param principalId Object ID of the AAD principal or security-group.
     * @param scope Scope at which the role assignment is created.
     * @param principalType Type of the principal Id: User, Group or ServicePrincipal.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role Assignment response details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RoleAssignmentDetails> createRoleAssignmentWithResponse(
            String roleAssignmentId,
            UUID roleId,
            UUID principalId,
            String scope,
            String principalType,
            Context context) {
        return createRoleAssignmentWithResponseAsync(
                        roleAssignmentId, roleId, principalId, scope, principalType, context)
                .block();
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<RoleAssignmentDetails>> getRoleAssignmentByIdWithResponseAsync(String roleAssignmentId) {
        final String accept = "application/json, text/json";
        return FluxUtil.withContext(
                context ->
                        service.getRoleAssignmentById(
                                this.client.getEndpoint(),
                                this.client.getApiVersion(),
                                roleAssignmentId,
                                accept,
                                context));
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<RoleAssignmentDetails>> getRoleAssignmentByIdWithResponseAsync(
            String roleAssignmentId, Context context) {
        final String accept = "application/json, text/json";
        return service.getRoleAssignmentById(
                this.client.getEndpoint(), this.client.getApiVersion(), roleAssignmentId, accept, context);
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetails> getRoleAssignmentByIdAsync(String roleAssignmentId) {
        return getRoleAssignmentByIdWithResponseAsync(roleAssignmentId)
                .flatMap(
                        (Response<RoleAssignmentDetails> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<RoleAssignmentDetails> getRoleAssignmentByIdAsync(String roleAssignmentId, Context context) {
        return getRoleAssignmentByIdWithResponseAsync(roleAssignmentId, context)
                .flatMap(
                        (Response<RoleAssignmentDetails> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleAssignmentDetails getRoleAssignmentById(String roleAssignmentId) {
        return getRoleAssignmentByIdAsync(roleAssignmentId).block();
    }

    /**
     * Get role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return role assignment by role assignment Id.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RoleAssignmentDetails> getRoleAssignmentByIdWithResponse(String roleAssignmentId, Context context) {
        return getRoleAssignmentByIdWithResponseAsync(roleAssignmentId, context).block();
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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>> deleteRoleAssignmentByIdWithResponseAsync(String roleAssignmentId, String scope) {
        final String accept = "application/json, text/json";
        return FluxUtil.withContext(
                context ->
                        service.deleteRoleAssignmentById(
                                this.client.getEndpoint(),
                                this.client.getApiVersion(),
                                roleAssignmentId,
                                scope,
                                accept,
                                context));
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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>> deleteRoleAssignmentByIdWithResponseAsync(
            String roleAssignmentId, String scope, Context context) {
        final String accept = "application/json, text/json";
        return service.deleteRoleAssignmentById(
                this.client.getEndpoint(), this.client.getApiVersion(), roleAssignmentId, scope, accept, context);
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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> deleteRoleAssignmentByIdAsync(String roleAssignmentId, String scope) {
        return deleteRoleAssignmentByIdWithResponseAsync(roleAssignmentId, scope)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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> deleteRoleAssignmentByIdAsync(String roleAssignmentId) {
        final String scope = null;
        return deleteRoleAssignmentByIdWithResponseAsync(roleAssignmentId, scope)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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> deleteRoleAssignmentByIdAsync(String roleAssignmentId, String scope, Context context) {
        return deleteRoleAssignmentByIdWithResponseAsync(roleAssignmentId, scope, context)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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 deleteRoleAssignmentById(String roleAssignmentId, String scope) {
        deleteRoleAssignmentByIdAsync(roleAssignmentId, scope).block();
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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 deleteRoleAssignmentById(String roleAssignmentId) {
        final String scope = null;
        deleteRoleAssignmentByIdAsync(roleAssignmentId, scope).block();
    }

    /**
     * Delete role assignment by role assignment Id.
     *
     * @param roleAssignmentId The ID of the role assignment.
     * @param scope Scope of the Synapse Built-in Role.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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> deleteRoleAssignmentByIdWithResponse(String roleAssignmentId, String scope, Context context) {
        return deleteRoleAssignmentByIdWithResponseAsync(roleAssignmentId, scope, context).block();
    }
}
