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

package com.azure.resourcemanager.policyinsights.implementation;

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.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.policyinsights.fluent.PolicyStatesClient;
import com.azure.resourcemanager.policyinsights.fluent.models.PolicyStateInner;
import com.azure.resourcemanager.policyinsights.fluent.models.SummarizeResultsInner;
import com.azure.resourcemanager.policyinsights.models.PolicyStatesQueryResults;
import com.azure.resourcemanager.policyinsights.models.PolicyStatesResource;
import com.azure.resourcemanager.policyinsights.models.PolicyStatesSummaryResourceType;
import java.nio.ByteBuffer;
import java.time.OffsetDateTime;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for PolicyInsightsClientPolicyStates to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "PolicyInsightsClient")
    private interface PolicyStatesService {
        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers"
                + "/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupName") String managementGroupName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers"
                + "/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupName") String managementGroupName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}"
                + "/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/policyStates/{policyStatesResource}/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/policyStates/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForResource(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$expand") String expand,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForResource(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> triggerSubscriptionEvaluation(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/policyStates/latest/triggerEvaluation")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> triggerResourceGroupEvaluation(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions"
                + "/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}"
                + "/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForPolicySetDefinition(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policySetDefinitionName") String policySetDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions"
                + "/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForPolicySetDefinition(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policySetDefinitionName") String policySetDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions"
                + "/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}"
                + "/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForPolicyDefinition(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyDefinitionName") String policyDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions"
                + "/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForPolicyDefinition(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyDefinitionName") String policyDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments"
                + "/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}"
                + "/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForSubscriptionLevelPolicyAssignment(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyAssignmentName") String policyAssignmentName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments"
                + "/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForSubscriptionLevelPolicyAssignment(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyAssignmentName") String policyAssignmentName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}"
                + "/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesResource}/queryResults")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PolicyStatesQueryResults>> listQueryResultsForResourceGroupLevelPolicyAssignment(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesResource") PolicyStatesResource policyStatesResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyAssignmentName") String policyAssignmentName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$orderby") String orderBy,
            @QueryParam("$select") String select,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @QueryParam("$apply") String apply,
            @QueryParam("$skiptoken") String skipToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}"
                + "/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates"
                + "/{policyStatesSummaryResource}/summarize")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SummarizeResultsInner>> summarizeForResourceGroupLevelPolicyAssignment(
            @HostParam("$host") String endpoint,
            @PathParam("policyStatesSummaryResource") PolicyStatesSummaryResourceType policyStatesSummaryResource,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("authorizationNamespace") String authorizationNamespace,
            @PathParam("policyAssignmentName") String policyAssignmentName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$top") Integer top,
            @QueryParam("$from") OffsetDateTime from,
            @QueryParam("$to") OffsetDateTime to,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForManagementGroupSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String managementGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (managementGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForManagementGroup(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            managementGroupsNamespace,
                            managementGroupName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForManagementGroupSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String managementGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (managementGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForManagementGroup(
                this.client.getEndpoint(),
                policyStatesResource,
                managementGroupsNamespace,
                managementGroupName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForManagementGroupAsync(
        PolicyStatesResource policyStatesResource,
        String managementGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForManagementGroupSinglePageAsync(
                    policyStatesResource,
                    managementGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForManagementGroupAsync(
        PolicyStatesResource policyStatesResource, String managementGroupName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForManagementGroupSinglePageAsync(
                    policyStatesResource,
                    managementGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForManagementGroupAsync(
        PolicyStatesResource policyStatesResource,
        String managementGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForManagementGroupSinglePageAsync(
                    policyStatesResource,
                    managementGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForManagementGroup(
        PolicyStatesResource policyStatesResource, String managementGroupName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForManagementGroupAsync(
                policyStatesResource, managementGroupName, top, orderBy, select, from, to, filter, apply, skipToken));
    }

    /**
     * Queries policy states for the resources under the management group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForManagementGroup(
        PolicyStatesResource policyStatesResource,
        String managementGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForManagementGroupAsync(
                policyStatesResource,
                managementGroupName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the resources under the management group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForManagementGroupWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String managementGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (managementGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForManagementGroup(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            managementGroupsNamespace,
                            managementGroupName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the resources under the management group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForManagementGroupWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String managementGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (managementGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForManagementGroup(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                managementGroupsNamespace,
                managementGroupName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the resources under the management group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param managementGroupName Management group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForManagementGroupAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String managementGroupName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForManagementGroupWithResponseAsync(
                policyStatesSummaryResource, managementGroupName, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the resources under the management group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param managementGroupName Management group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForManagementGroupWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String managementGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForManagementGroupWithResponseAsync(
                policyStatesSummaryResource, managementGroupName, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the resources under the management group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param managementGroupName Management group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForManagementGroup(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String managementGroupName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForManagementGroupWithResponse(
                policyStatesSummaryResource, managementGroupName, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForSubscriptionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForSubscription(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForSubscriptionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForSubscription(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionSinglePageAsync(
                    policyStatesResource, subscriptionId, top, orderBy, select, from, to, filter, apply, skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionAsync(
        PolicyStatesResource policyStatesResource, String subscriptionId) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionSinglePageAsync(
                    policyStatesResource, subscriptionId, top, orderBy, select, from, to, filter, apply, skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForSubscription(
        PolicyStatesResource policyStatesResource, String subscriptionId) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForSubscriptionAsync(
                policyStatesResource, subscriptionId, top, orderBy, select, from, to, filter, apply, skipToken));
    }

    /**
     * Queries policy states for the resources under the subscription.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForSubscription(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForSubscriptionAsync(
                policyStatesResource,
                subscriptionId,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the resources under the subscription.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForSubscriptionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForSubscription(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the resources under the subscription.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForSubscriptionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForSubscription(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the resources under the subscription.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForSubscriptionAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String subscriptionId) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForSubscriptionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the resources under the subscription.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForSubscriptionWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForSubscriptionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the resources under the subscription.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForSubscription(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String subscriptionId) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForSubscriptionWithResponse(
                policyStatesSummaryResource, subscriptionId, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceGroupSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForResourceGroup(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            resourceGroupName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceGroupSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForResourceGroup(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupAsync(
        PolicyStatesResource policyStatesResource, String subscriptionId, String resourceGroupName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResourceGroup(
        PolicyStatesResource policyStatesResource, String subscriptionId, String resourceGroupName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForResourceGroupAsync(
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken));
    }

    /**
     * Queries policy states for the resources under the resource group.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResourceGroup(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForResourceGroupAsync(
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the resources under the resource group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceGroupWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForResourceGroup(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            resourceGroupName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the resources under the resource group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceGroupWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForResourceGroup(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                resourceGroupName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the resources under the resource group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForResourceGroupAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String subscriptionId, String resourceGroupName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceGroupWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, resourceGroupName, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the resources under the resource group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForResourceGroupWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForResourceGroupWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, resourceGroupName, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the resources under the resource group.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForResourceGroup(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String subscriptionId, String resourceGroupName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceGroupWithResponse(
                policyStatesSummaryResource, subscriptionId, resourceGroupName, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param expand The $expand query parameter. For example, to expand components use $expand=components.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String resourceId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String expand,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForResource(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            resourceId,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            expand,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param expand The $expand query parameter. For example, to expand components use $expand=components.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String resourceId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String expand,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForResource(
                this.client.getEndpoint(),
                policyStatesResource,
                resourceId,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                expand,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param expand The $expand query parameter. For example, to expand components use $expand=components.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceAsync(
        PolicyStatesResource policyStatesResource,
        String resourceId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String expand,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceSinglePageAsync(
                    policyStatesResource, resourceId, top, orderBy, select, from, to, filter, apply, expand, skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceAsync(
        PolicyStatesResource policyStatesResource, String resourceId) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String expand = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceSinglePageAsync(
                    policyStatesResource, resourceId, top, orderBy, select, from, to, filter, apply, expand, skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param expand The $expand query parameter. For example, to expand components use $expand=components.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceAsync(
        PolicyStatesResource policyStatesResource,
        String resourceId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String expand,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceSinglePageAsync(
                    policyStatesResource,
                    resourceId,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    expand,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResource(
        PolicyStatesResource policyStatesResource, String resourceId) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String expand = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForResourceAsync(
                policyStatesResource, resourceId, top, orderBy, select, from, to, filter, apply, expand, skipToken));
    }

    /**
     * Queries policy states for the resource.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param expand The $expand query parameter. For example, to expand components use $expand=components.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResource(
        PolicyStatesResource policyStatesResource,
        String resourceId,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String expand,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForResourceAsync(
                policyStatesResource,
                resourceId,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                expand,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the resource.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String resourceId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForResource(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            resourceId,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the resource.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String resourceId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForResource(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                resourceId,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the resource.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param resourceId Resource ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForResourceAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String resourceId) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceWithResponseAsync(policyStatesSummaryResource, resourceId, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the resource.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForResourceWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String resourceId,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForResourceWithResponseAsync(
                policyStatesSummaryResource, resourceId, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the resource.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param resourceId Resource ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForResource(
        PolicyStatesSummaryResourceType policyStatesSummaryResource, String resourceId) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceWithResponse(
                policyStatesSummaryResource, resourceId, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> triggerSubscriptionEvaluationWithResponseAsync(String subscriptionId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .triggerSubscriptionEvaluation(
                            this.client.getEndpoint(), subscriptionId, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> triggerSubscriptionEvaluationWithResponseAsync(
        String subscriptionId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .triggerSubscriptionEvaluation(this.client.getEndpoint(), subscriptionId, apiVersion, accept, context);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginTriggerSubscriptionEvaluationAsync(String subscriptionId) {
        Mono<Response<Flux<ByteBuffer>>> mono = triggerSubscriptionEvaluationWithResponseAsync(subscriptionId);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginTriggerSubscriptionEvaluationAsync(
        String subscriptionId, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = triggerSubscriptionEvaluationWithResponseAsync(subscriptionId, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginTriggerSubscriptionEvaluation(String subscriptionId) {
        return beginTriggerSubscriptionEvaluationAsync(subscriptionId).getSyncPoller();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginTriggerSubscriptionEvaluation(
        String subscriptionId, Context context) {
        return beginTriggerSubscriptionEvaluationAsync(subscriptionId, context).getSyncPoller();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> triggerSubscriptionEvaluationAsync(String subscriptionId) {
        return beginTriggerSubscriptionEvaluationAsync(subscriptionId)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> triggerSubscriptionEvaluationAsync(String subscriptionId, Context context) {
        return beginTriggerSubscriptionEvaluationAsync(subscriptionId, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void triggerSubscriptionEvaluation(String subscriptionId) {
        triggerSubscriptionEvaluationAsync(subscriptionId).block();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the subscription.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void triggerSubscriptionEvaluation(String subscriptionId, Context context) {
        triggerSubscriptionEvaluationAsync(subscriptionId, context).block();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> triggerResourceGroupEvaluationWithResponseAsync(
        String subscriptionId, String resourceGroupName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .triggerResourceGroupEvaluation(
                            this.client.getEndpoint(), subscriptionId, resourceGroupName, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> triggerResourceGroupEvaluationWithResponseAsync(
        String subscriptionId, String resourceGroupName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .triggerResourceGroupEvaluation(
                this.client.getEndpoint(), subscriptionId, resourceGroupName, apiVersion, accept, context);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginTriggerResourceGroupEvaluationAsync(
        String subscriptionId, String resourceGroupName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            triggerResourceGroupEvaluationWithResponseAsync(subscriptionId, resourceGroupName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginTriggerResourceGroupEvaluationAsync(
        String subscriptionId, String resourceGroupName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            triggerResourceGroupEvaluationWithResponseAsync(subscriptionId, resourceGroupName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginTriggerResourceGroupEvaluation(
        String subscriptionId, String resourceGroupName) {
        return beginTriggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName).getSyncPoller();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginTriggerResourceGroupEvaluation(
        String subscriptionId, String resourceGroupName, Context context) {
        return beginTriggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName, context).getSyncPoller();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> triggerResourceGroupEvaluationAsync(String subscriptionId, String resourceGroupName) {
        return beginTriggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> triggerResourceGroupEvaluationAsync(
        String subscriptionId, String resourceGroupName, Context context) {
        return beginTriggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void triggerResourceGroupEvaluation(String subscriptionId, String resourceGroupName) {
        triggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName).block();
    }

    /**
     * Triggers a policy evaluation scan for all the resources under the resource group.
     *
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void triggerResourceGroupEvaluation(String subscriptionId, String resourceGroupName, Context context) {
        triggerResourceGroupEvaluationAsync(subscriptionId, resourceGroupName, context).block();
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForPolicySetDefinitionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policySetDefinitionName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter policySetDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForPolicySetDefinition(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            authorizationNamespace,
                            policySetDefinitionName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForPolicySetDefinitionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policySetDefinitionName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter policySetDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForPolicySetDefinition(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                authorizationNamespace,
                policySetDefinitionName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicySetDefinitionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicySetDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policySetDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicySetDefinitionAsync(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policySetDefinitionName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicySetDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policySetDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicySetDefinitionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicySetDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policySetDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForPolicySetDefinition(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policySetDefinitionName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForPolicySetDefinitionAsync(
                policyStatesResource,
                subscriptionId,
                policySetDefinitionName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken));
    }

    /**
     * Queries policy states for the subscription level policy set definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForPolicySetDefinition(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForPolicySetDefinitionAsync(
                policyStatesResource,
                subscriptionId,
                policySetDefinitionName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the subscription level policy set definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForPolicySetDefinitionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policySetDefinitionName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter policySetDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForPolicySetDefinition(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            authorizationNamespace,
                            policySetDefinitionName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the subscription level policy set definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForPolicySetDefinitionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policySetDefinitionName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter policySetDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForPolicySetDefinition(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                authorizationNamespace,
                policySetDefinitionName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the subscription level policy set definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForPolicySetDefinitionAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policySetDefinitionName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForPolicySetDefinitionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policySetDefinitionName, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the subscription level policy set definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForPolicySetDefinitionWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policySetDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForPolicySetDefinitionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policySetDefinitionName, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the subscription level policy set definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policySetDefinitionName Policy set definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForPolicySetDefinition(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policySetDefinitionName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForPolicySetDefinitionWithResponse(
                policyStatesSummaryResource,
                subscriptionId,
                policySetDefinitionName,
                top,
                from,
                to,
                filter,
                Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForPolicyDefinitionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForPolicyDefinition(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            authorizationNamespace,
                            policyDefinitionName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForPolicyDefinitionSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForPolicyDefinition(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                authorizationNamespace,
                policyDefinitionName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicyDefinitionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicyDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicyDefinitionAsync(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policyDefinitionName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicyDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForPolicyDefinitionAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForPolicyDefinitionSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyDefinitionName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForPolicyDefinition(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policyDefinitionName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForPolicyDefinitionAsync(
                policyStatesResource,
                subscriptionId,
                policyDefinitionName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken));
    }

    /**
     * Queries policy states for the subscription level policy definition.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForPolicyDefinition(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForPolicyDefinitionAsync(
                policyStatesResource,
                subscriptionId,
                policyDefinitionName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the subscription level policy definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForPolicyDefinitionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForPolicyDefinition(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            authorizationNamespace,
                            policyDefinitionName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the subscription level policy definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForPolicyDefinitionWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyDefinitionName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForPolicyDefinition(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                authorizationNamespace,
                policyDefinitionName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the subscription level policy definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForPolicyDefinitionAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyDefinitionName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForPolicyDefinitionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policyDefinitionName, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the subscription level policy definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForPolicyDefinitionWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyDefinitionName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForPolicyDefinitionWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policyDefinitionName, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the subscription level policy definition.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyDefinitionName Policy definition name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForPolicyDefinition(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyDefinitionName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForPolicyDefinitionWithResponse(
                policyStatesSummaryResource, subscriptionId, policyDefinitionName, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForSubscriptionLevelPolicyAssignmentSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForSubscriptionLevelPolicyAssignment(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            authorizationNamespace,
                            policyAssignmentName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForSubscriptionLevelPolicyAssignmentSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForSubscriptionLevelPolicyAssignment(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                authorizationNamespace,
                policyAssignmentName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policyAssignmentName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForSubscriptionLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForSubscriptionLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForSubscriptionLevelPolicyAssignment(
        PolicyStatesResource policyStatesResource, String subscriptionId, String policyAssignmentName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForSubscriptionLevelPolicyAssignmentAsync(
                policyStatesResource,
                subscriptionId,
                policyAssignmentName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken));
    }

    /**
     * Queries policy states for the subscription level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForSubscriptionLevelPolicyAssignment(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForSubscriptionLevelPolicyAssignmentAsync(
                policyStatesResource,
                subscriptionId,
                policyAssignmentName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the subscription level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForSubscriptionLevelPolicyAssignmentWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForSubscriptionLevelPolicyAssignment(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            authorizationNamespace,
                            policyAssignmentName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the subscription level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForSubscriptionLevelPolicyAssignmentWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForSubscriptionLevelPolicyAssignment(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                authorizationNamespace,
                policyAssignmentName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the subscription level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForSubscriptionLevelPolicyAssignmentAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyAssignmentName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForSubscriptionLevelPolicyAssignmentWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policyAssignmentName, top, from, to, filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the subscription level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForSubscriptionLevelPolicyAssignmentWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForSubscriptionLevelPolicyAssignmentWithResponseAsync(
                policyStatesSummaryResource, subscriptionId, policyAssignmentName, top, from, to, filter, context)
            .block();
    }

    /**
     * Summarizes policy states for the subscription level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForSubscriptionLevelPolicyAssignment(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String policyAssignmentName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForSubscriptionLevelPolicyAssignmentWithResponse(
                policyStatesSummaryResource, subscriptionId, policyAssignmentName, top, from, to, filter, Context.NONE)
            .getValue();
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceGroupLevelPolicyAssignmentSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listQueryResultsForResourceGroupLevelPolicyAssignment(
                            this.client.getEndpoint(),
                            policyStatesResource,
                            subscriptionId,
                            resourceGroupName,
                            authorizationNamespace,
                            policyAssignmentName,
                            apiVersion,
                            top,
                            orderBy,
                            select,
                            from,
                            to,
                            filter,
                            apply,
                            skipToken,
                            accept,
                            context))
            .<PagedResponse<PolicyStateInner>>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()));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> listQueryResultsForResourceGroupLevelPolicyAssignmentSinglePageAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesResource == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyStatesResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listQueryResultsForResourceGroupLevelPolicyAssignment(
                this.client.getEndpoint(),
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                authorizationNamespace,
                policyAssignmentName,
                apiVersion,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken),
            nextLink -> nextLinkSinglePageAsync(nextLink));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PolicyStateInner> listQueryResultsForResourceGroupLevelPolicyAssignmentAsync(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedFlux<>(
            () ->
                listQueryResultsForResourceGroupLevelPolicyAssignmentSinglePageAsync(
                    policyStatesResource,
                    subscriptionId,
                    resourceGroupName,
                    policyAssignmentName,
                    top,
                    orderBy,
                    select,
                    from,
                    to,
                    filter,
                    apply,
                    skipToken,
                    context),
            nextLink -> nextLinkSinglePageAsync(nextLink, context));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResourceGroupLevelPolicyAssignment(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName) {
        final Integer top = null;
        final String orderBy = null;
        final String select = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        final String apply = null;
        final String skipToken = null;
        return new PagedIterable<>(
            listQueryResultsForResourceGroupLevelPolicyAssignmentAsync(
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                policyAssignmentName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken));
    }

    /**
     * Queries policy states for the resource group level policy assignment.
     *
     * @param policyStatesResource The virtual resource under PolicyStates resource type. In a given time range,
     *     'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param orderBy Ordering expression using OData notation. One or more comma-separated column names with an
     *     optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".
     * @param select Select expression using OData notation. Limits the columns on each record to just those requested,
     *     e.g. "$select=PolicyAssignmentId, ResourceId".
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param apply OData apply expression for aggregations.
     * @param skipToken Skiptoken is only provided if a previous response returned a partial result as a part of
     *     nextLink element.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PolicyStateInner> listQueryResultsForResourceGroupLevelPolicyAssignment(
        PolicyStatesResource policyStatesResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        String orderBy,
        String select,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        String apply,
        String skipToken,
        Context context) {
        return new PagedIterable<>(
            listQueryResultsForResourceGroupLevelPolicyAssignmentAsync(
                policyStatesResource,
                subscriptionId,
                resourceGroupName,
                policyAssignmentName,
                top,
                orderBy,
                select,
                from,
                to,
                filter,
                apply,
                skipToken,
                context));
    }

    /**
     * Summarizes policy states for the resource group level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceGroupLevelPolicyAssignmentWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .summarizeForResourceGroupLevelPolicyAssignment(
                            this.client.getEndpoint(),
                            policyStatesSummaryResource,
                            subscriptionId,
                            resourceGroupName,
                            authorizationNamespace,
                            policyAssignmentName,
                            apiVersion,
                            top,
                            from,
                            to,
                            filter,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Summarizes policy states for the resource group level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SummarizeResultsInner>> summarizeForResourceGroupLevelPolicyAssignmentWithResponseAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        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 (policyStatesSummaryResource == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter policyStatesSummaryResource is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (policyAssignmentName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter policyAssignmentName is required and cannot be null."));
        }
        final String authorizationNamespace = "Microsoft.Authorization";
        final String apiVersion = "2019-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .summarizeForResourceGroupLevelPolicyAssignment(
                this.client.getEndpoint(),
                policyStatesSummaryResource,
                subscriptionId,
                resourceGroupName,
                authorizationNamespace,
                policyAssignmentName,
                apiVersion,
                top,
                from,
                to,
                filter,
                accept,
                context);
    }

    /**
     * Summarizes policy states for the resource group level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SummarizeResultsInner> summarizeForResourceGroupLevelPolicyAssignmentAsync(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceGroupLevelPolicyAssignmentWithResponseAsync(
                policyStatesSummaryResource,
                subscriptionId,
                resourceGroupName,
                policyAssignmentName,
                top,
                from,
                to,
                filter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Summarizes policy states for the resource group level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @param top Maximum number of records to return.
     * @param from ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified,
     *     the service uses ($to - 1-day).
     * @param to ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the
     *     service uses request time.
     * @param filter OData filter expression.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SummarizeResultsInner> summarizeForResourceGroupLevelPolicyAssignmentWithResponse(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName,
        Integer top,
        OffsetDateTime from,
        OffsetDateTime to,
        String filter,
        Context context) {
        return summarizeForResourceGroupLevelPolicyAssignmentWithResponseAsync(
                policyStatesSummaryResource,
                subscriptionId,
                resourceGroupName,
                policyAssignmentName,
                top,
                from,
                to,
                filter,
                context)
            .block();
    }

    /**
     * Summarizes policy states for the resource group level policy assignment.
     *
     * @param policyStatesSummaryResource The virtual resource under PolicyStates resource type for summarize action. In
     *     a given time range, 'latest' represents the latest policy state(s) and is the only allowed value.
     * @param subscriptionId Microsoft Azure subscription ID.
     * @param resourceGroupName Resource group name.
     * @param policyAssignmentName Policy assignment name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return summarize action results.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SummarizeResultsInner summarizeForResourceGroupLevelPolicyAssignment(
        PolicyStatesSummaryResourceType policyStatesSummaryResource,
        String subscriptionId,
        String resourceGroupName,
        String policyAssignmentName) {
        final Integer top = null;
        final OffsetDateTime from = null;
        final OffsetDateTime to = null;
        final String filter = null;
        return summarizeForResourceGroupLevelPolicyAssignmentWithResponse(
                policyStatesSummaryResource,
                subscriptionId,
                resourceGroupName,
                policyAssignmentName,
                top,
                from,
                to,
                filter,
                Context.NONE)
            .getValue();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> nextLinkSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        return FluxUtil
            .withContext(context -> service.nextLink(nextLink, context))
            .<PagedResponse<PolicyStateInner>>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 URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return query results along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PolicyStateInner>> nextLinkSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        context = this.client.mergeContext(context);
        return service
            .nextLink(nextLink, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().odataNextLink(),
                        null));
    }
}
