# pylint: disable=too-many-lines
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import datetime
import sys
from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast

from azure.core.exceptions import (
    ClientAuthenticationError,
    HttpResponseError,
    ResourceExistsError,
    ResourceNotFoundError,
    ResourceNotModifiedError,
    map_error,
)
from azure.core.paging import ItemPaged
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpResponse
from azure.core.polling import LROPoller, NoPolling, PollingMethod
from azure.core.rest import HttpRequest
from azure.core.tracing.decorator import distributed_trace
from azure.core.utils import case_insensitive_dict
from azure.mgmt.core.exceptions import ARMErrorFormat
from azure.mgmt.core.polling.arm_polling import ARMPolling

from .. import models as _models
from .._serialization import Serializer
from .._vendor import _convert_request, _format_url_section

if sys.version_info >= (3, 8):
    from typing import Literal  # pylint: disable=no-name-in-module, ungrouped-imports
else:
    from typing_extensions import Literal  # type: ignore  # pylint: disable=ungrouped-imports
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]

_SERIALIZER = Serializer()
_SERIALIZER.client_side_validation = False


def build_list_query_results_for_management_group_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    management_group_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    management_groups_namespace: Literal["Microsoft.Management"] = kwargs.pop(
        "management_groups_namespace", "Microsoft.Management"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "managementGroupsNamespace": _SERIALIZER.url("management_groups_namespace", management_groups_namespace, "str"),
        "managementGroupName": _SERIALIZER.url("management_group_name", management_group_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_management_group_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    management_group_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    management_groups_namespace: Literal["Microsoft.Management"] = kwargs.pop(
        "management_groups_namespace", "Microsoft.Management"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "managementGroupsNamespace": _SERIALIZER.url("management_groups_namespace", management_groups_namespace, "str"),
        "managementGroupName": _SERIALIZER.url("management_group_name", management_group_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_subscription_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_subscription_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_resource_group_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    resource_group_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_resource_group_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    resource_group_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_resource_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    resource_id: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    expand: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "resourceId": _SERIALIZER.url("resource_id", resource_id, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if expand is not None:
        _params["$expand"] = _SERIALIZER.query("expand", expand, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_resource_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    resource_id: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "resourceId": _SERIALIZER.url("resource_id", resource_id, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_trigger_subscription_evaluation_request(subscription_id: str, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_trigger_resource_group_evaluation_request(
    subscription_id: str, resource_group_name: str, **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_policy_set_definition_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    policy_set_definition_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_policy_set_definition_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    policy_set_definition_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_policy_definition_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    policy_definition_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_policy_definition_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    policy_definition_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_subscription_level_policy_assignment_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    policy_assignment_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_subscription_level_policy_assignment_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    policy_assignment_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_list_query_results_for_resource_group_level_policy_assignment_request(
    policy_states_resource: Union[str, _models.PolicyStatesResource],
    subscription_id: str,
    resource_group_name: str,
    policy_assignment_name: str,
    *,
    top: Optional[int] = None,
    order_by: Optional[str] = None,
    select: Optional[str] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    apply: Optional[str] = None,
    skip_token: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesResource": _SERIALIZER.url("policy_states_resource", policy_states_resource, "str"),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if order_by is not None:
        _params["$orderby"] = _SERIALIZER.query("order_by", order_by, "str")
    if select is not None:
        _params["$select"] = _SERIALIZER.query("select", select, "str")
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")
    if apply is not None:
        _params["$apply"] = _SERIALIZER.query("apply", apply, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_next_link_request(next_link: str, *, skip_token: Optional[str] = None, **kwargs: Any) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop("template_url", "{nextLink}")
    path_format_arguments = {
        "nextLink": _SERIALIZER.url("next_link", next_link, "str", skip_quote=True),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if skip_token is not None:
        _params["$skiptoken"] = _SERIALIZER.query("skip_token", skip_token, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


def build_summarize_for_resource_group_level_policy_assignment_request(
    policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
    subscription_id: str,
    resource_group_name: str,
    policy_assignment_name: str,
    *,
    top: Optional[int] = None,
    from_property: Optional[datetime.datetime] = None,
    to: Optional[datetime.datetime] = None,
    filter: Optional[str] = None,
    **kwargs: Any
) -> HttpRequest:
    _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
    _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

    authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
        "authorization_namespace", "Microsoft.Authorization"
    )
    api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
    accept = _headers.pop("Accept", "application/json")

    # Construct URL
    _url = kwargs.pop(
        "template_url",
        "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize",
    )  # pylint: disable=line-too-long
    path_format_arguments = {
        "policyStatesSummaryResource": _SERIALIZER.url(
            "policy_states_summary_resource", policy_states_summary_resource, "str"
        ),
        "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"),
        "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"),
        "authorizationNamespace": _SERIALIZER.url("authorization_namespace", authorization_namespace, "str"),
        "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"),
    }

    _url: str = _format_url_section(_url, **path_format_arguments)  # type: ignore

    # Construct parameters
    _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
    if top is not None:
        _params["$top"] = _SERIALIZER.query("top", top, "int", minimum=0)
    if from_property is not None:
        _params["$from"] = _SERIALIZER.query("from_property", from_property, "iso-8601")
    if to is not None:
        _params["$to"] = _SERIALIZER.query("to", to, "iso-8601")
    if filter is not None:
        _params["$filter"] = _SERIALIZER.query("filter", filter, "str")

    # Construct headers
    _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")

    return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


class PolicyStatesOperations:
    """
    .. warning::
        **DO NOT** instantiate this class directly.

        Instead, you should access the following operations through
        :class:`~azure.mgmt.policyinsights.PolicyInsightsClient`'s
        :attr:`policy_states` attribute.
    """

    models = _models

    def __init__(self, *args, **kwargs):
        input_args = list(args)
        self._client = input_args.pop(0) if input_args else kwargs.pop("client")
        self._config = input_args.pop(0) if input_args else kwargs.pop("config")
        self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
        self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")

    @distributed_trace
    def list_query_results_for_management_group(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        management_group_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the resources under the management group.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param management_group_name: Management group name. Required.
        :type management_group_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword management_groups_namespace: The namespace for Microsoft Management RP; only
         "Microsoft.Management" is allowed. Default value is "Microsoft.Management". Note that
         overriding this default value may result in unsupported behavior.
        :paramtype management_groups_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        management_groups_namespace: Literal["Microsoft.Management"] = kwargs.pop(
            "management_groups_namespace", "Microsoft.Management"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_management_group_request(
                    policy_states_resource=policy_states_resource,
                    management_group_name=management_group_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    management_groups_namespace=management_groups_namespace,
                    api_version=api_version,
                    template_url=self.list_query_results_for_management_group.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_management_group.metadata = {
        "url": "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_management_group(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        management_group_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the resources under the management group.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param management_group_name: Management group name. Required.
        :type management_group_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword management_groups_namespace: The namespace for Microsoft Management RP; only
         "Microsoft.Management" is allowed. Default value is "Microsoft.Management". Note that
         overriding this default value may result in unsupported behavior.
        :paramtype management_groups_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        management_groups_namespace: Literal["Microsoft.Management"] = kwargs.pop(
            "management_groups_namespace", "Microsoft.Management"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_management_group_request(
            policy_states_summary_resource=policy_states_summary_resource,
            management_group_name=management_group_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            management_groups_namespace=management_groups_namespace,
            api_version=api_version,
            template_url=self.summarize_for_management_group.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_management_group.metadata = {
        "url": "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_subscription(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the resources under the subscription.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_subscription_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url=self.list_query_results_for_subscription.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_subscription.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_subscription(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the resources under the subscription.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_subscription_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            api_version=api_version,
            template_url=self.summarize_for_subscription.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_subscription.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_resource_group(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        resource_group_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the resources under the resource group.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param resource_group_name: Resource group name. Required.
        :type resource_group_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_resource_group_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    resource_group_name=resource_group_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url=self.list_query_results_for_resource_group.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_resource_group.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_resource_group(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        resource_group_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the resources under the resource group.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param resource_group_name: Resource group name. Required.
        :type resource_group_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_resource_group_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            resource_group_name=resource_group_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            api_version=api_version,
            template_url=self.summarize_for_resource_group.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_resource_group.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_resource(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        resource_id: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the resource.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param resource_id: Resource ID. Required.
        :type resource_id: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _expand = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _expand = query_options.expand
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_resource_request(
                    policy_states_resource=policy_states_resource,
                    resource_id=resource_id,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    expand=_expand,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url=self.list_query_results_for_resource.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _expand = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _expand = query_options.expand
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_resource.metadata = {
        "url": "/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_resource(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        resource_id: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the resource.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param resource_id: Resource ID. Required.
        :type resource_id: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_resource_request(
            policy_states_summary_resource=policy_states_summary_resource,
            resource_id=resource_id,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            api_version=api_version,
            template_url=self.summarize_for_resource.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_resource.metadata = {
        "url": "/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    def _trigger_subscription_evaluation_initial(  # pylint: disable=inconsistent-return-statements
        self, subscription_id: str, **kwargs: Any
    ) -> None:
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[None] = kwargs.pop("cls", None)

        request = build_trigger_subscription_evaluation_request(
            subscription_id=subscription_id,
            api_version=api_version,
            template_url=self._trigger_subscription_evaluation_initial.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200, 202]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        if cls:
            return cls(pipeline_response, None, {})

    _trigger_subscription_evaluation_initial.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation"
    }

    @distributed_trace
    def begin_trigger_subscription_evaluation(self, subscription_id: str, **kwargs: Any) -> LROPoller[None]:
        """Triggers a policy evaluation scan for all the resources under the subscription.

        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :keyword str continuation_token: A continuation token to restart a poller from a saved state.
        :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this
         operation to not poll, or pass in your own initialized polling object for a personal polling
         strategy.
        :paramtype polling: bool or ~azure.core.polling.PollingMethod
        :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
         Retry-After header is present.
        :return: An instance of LROPoller that returns either None or the result of cls(response)
        :rtype: ~azure.core.polling.LROPoller[None]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[None] = kwargs.pop("cls", None)
        polling: Union[bool, PollingMethod] = kwargs.pop("polling", True)
        lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
        cont_token: Optional[str] = kwargs.pop("continuation_token", None)
        if cont_token is None:
            raw_result = self._trigger_subscription_evaluation_initial(  # type: ignore
                subscription_id=subscription_id,
                api_version=api_version,
                cls=lambda x, y, z: x,
                headers=_headers,
                params=_params,
                **kwargs
            )
        kwargs.pop("error_map", None)

        def get_long_running_output(pipeline_response):  # pylint: disable=inconsistent-return-statements
            if cls:
                return cls(pipeline_response, None, {})

        if polling is True:
            polling_method: PollingMethod = cast(
                PollingMethod, ARMPolling(lro_delay, lro_options={"final-state-via": "location"}, **kwargs)
            )
        elif polling is False:
            polling_method = cast(PollingMethod, NoPolling())
        else:
            polling_method = polling
        if cont_token:
            return LROPoller.from_continuation_token(
                polling_method=polling_method,
                continuation_token=cont_token,
                client=self._client,
                deserialization_callback=get_long_running_output,
            )
        return LROPoller(self._client, raw_result, get_long_running_output, polling_method)  # type: ignore

    begin_trigger_subscription_evaluation.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation"
    }

    def _trigger_resource_group_evaluation_initial(  # pylint: disable=inconsistent-return-statements
        self, subscription_id: str, resource_group_name: str, **kwargs: Any
    ) -> None:
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[None] = kwargs.pop("cls", None)

        request = build_trigger_resource_group_evaluation_request(
            subscription_id=subscription_id,
            resource_group_name=resource_group_name,
            api_version=api_version,
            template_url=self._trigger_resource_group_evaluation_initial.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200, 202]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        if cls:
            return cls(pipeline_response, None, {})

    _trigger_resource_group_evaluation_initial.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation"
    }

    @distributed_trace
    def begin_trigger_resource_group_evaluation(
        self, subscription_id: str, resource_group_name: str, **kwargs: Any
    ) -> LROPoller[None]:
        """Triggers a policy evaluation scan for all the resources under the resource group.

        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param resource_group_name: Resource group name. Required.
        :type resource_group_name: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :keyword str continuation_token: A continuation token to restart a poller from a saved state.
        :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this
         operation to not poll, or pass in your own initialized polling object for a personal polling
         strategy.
        :paramtype polling: bool or ~azure.core.polling.PollingMethod
        :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
         Retry-After header is present.
        :return: An instance of LROPoller that returns either None or the result of cls(response)
        :rtype: ~azure.core.polling.LROPoller[None]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[None] = kwargs.pop("cls", None)
        polling: Union[bool, PollingMethod] = kwargs.pop("polling", True)
        lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
        cont_token: Optional[str] = kwargs.pop("continuation_token", None)
        if cont_token is None:
            raw_result = self._trigger_resource_group_evaluation_initial(  # type: ignore
                subscription_id=subscription_id,
                resource_group_name=resource_group_name,
                api_version=api_version,
                cls=lambda x, y, z: x,
                headers=_headers,
                params=_params,
                **kwargs
            )
        kwargs.pop("error_map", None)

        def get_long_running_output(pipeline_response):  # pylint: disable=inconsistent-return-statements
            if cls:
                return cls(pipeline_response, None, {})

        if polling is True:
            polling_method: PollingMethod = cast(
                PollingMethod, ARMPolling(lro_delay, lro_options={"final-state-via": "location"}, **kwargs)
            )
        elif polling is False:
            polling_method = cast(PollingMethod, NoPolling())
        else:
            polling_method = polling
        if cont_token:
            return LROPoller.from_continuation_token(
                polling_method=polling_method,
                continuation_token=cont_token,
                client=self._client,
                deserialization_callback=get_long_running_output,
            )
        return LROPoller(self._client, raw_result, get_long_running_output, polling_method)  # type: ignore

    begin_trigger_resource_group_evaluation.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation"
    }

    @distributed_trace
    def list_query_results_for_policy_set_definition(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        policy_set_definition_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the subscription level policy set definition.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_set_definition_name: Policy set definition name. Required.
        :type policy_set_definition_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_policy_set_definition_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    policy_set_definition_name=policy_set_definition_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    authorization_namespace=authorization_namespace,
                    api_version=api_version,
                    template_url=self.list_query_results_for_policy_set_definition.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_policy_set_definition.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_policy_set_definition(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        policy_set_definition_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the subscription level policy set definition.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_set_definition_name: Policy set definition name. Required.
        :type policy_set_definition_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_policy_set_definition_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            policy_set_definition_name=policy_set_definition_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            authorization_namespace=authorization_namespace,
            api_version=api_version,
            template_url=self.summarize_for_policy_set_definition.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_policy_set_definition.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_policy_definition(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        policy_definition_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the subscription level policy definition.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_definition_name: Policy definition name. Required.
        :type policy_definition_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_policy_definition_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    policy_definition_name=policy_definition_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    authorization_namespace=authorization_namespace,
                    api_version=api_version,
                    template_url=self.list_query_results_for_policy_definition.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_policy_definition.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_policy_definition(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        policy_definition_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the subscription level policy definition.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_definition_name: Policy definition name. Required.
        :type policy_definition_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_policy_definition_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            policy_definition_name=policy_definition_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            authorization_namespace=authorization_namespace,
            api_version=api_version,
            template_url=self.summarize_for_policy_definition.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_policy_definition.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_subscription_level_policy_assignment(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        policy_assignment_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the subscription level policy assignment.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_assignment_name: Policy assignment name. Required.
        :type policy_assignment_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_subscription_level_policy_assignment_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    policy_assignment_name=policy_assignment_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    authorization_namespace=authorization_namespace,
                    api_version=api_version,
                    template_url=self.list_query_results_for_subscription_level_policy_assignment.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_subscription_level_policy_assignment.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_subscription_level_policy_assignment(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        policy_assignment_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the subscription level policy assignment.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param policy_assignment_name: Policy assignment name. Required.
        :type policy_assignment_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_subscription_level_policy_assignment_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            policy_assignment_name=policy_assignment_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            authorization_namespace=authorization_namespace,
            api_version=api_version,
            template_url=self.summarize_for_subscription_level_policy_assignment.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_subscription_level_policy_assignment.metadata = {
        "url": "/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }

    @distributed_trace
    def list_query_results_for_resource_group_level_policy_assignment(
        self,
        policy_states_resource: Union[str, _models.PolicyStatesResource],
        subscription_id: str,
        resource_group_name: str,
        policy_assignment_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> Iterable["_models.PolicyState"]:
        """Queries policy states for the resource group level policy assignment.

        :param policy_states_resource: 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). Known values are: "default" and "latest". Required.
        :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param resource_group_name: Resource group name. Required.
        :type resource_group_name: str
        :param policy_assignment_name: Policy assignment name. Required.
        :type policy_assignment_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: An iterator like instance of either PolicyState or the result of cls(response)
        :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyState]
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.PolicyStatesQueryResults] = kwargs.pop("cls", None)

        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        def prepare_request(next_link=None):
            if not next_link:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_list_query_results_for_resource_group_level_policy_assignment_request(
                    policy_states_resource=policy_states_resource,
                    subscription_id=subscription_id,
                    resource_group_name=resource_group_name,
                    policy_assignment_name=policy_assignment_name,
                    top=_top,
                    order_by=_order_by,
                    select=_select,
                    from_property=_from_property,
                    to=_to,
                    filter=_filter,
                    apply=_apply,
                    skip_token=_skip_token,
                    authorization_namespace=authorization_namespace,
                    api_version=api_version,
                    template_url=self.list_query_results_for_resource_group_level_policy_assignment.metadata["url"],
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            else:
                _top = None
                _order_by = None
                _select = None
                _from_property = None
                _to = None
                _filter = None
                _apply = None
                _skip_token = None
                if query_options is not None:
                    _apply = query_options.apply
                    _filter = query_options.filter
                    _from_property = query_options.from_property
                    _order_by = query_options.order_by
                    _select = query_options.select
                    _skip_token = query_options.skip_token
                    _to = query_options.to
                    _top = query_options.top

                request = build_next_link_request(
                    next_link=next_link,
                    skip_token=_skip_token,
                    api_version=api_version,
                    template_url="{nextLink}",
                    headers=_headers,
                    params=_params,
                )
                request = _convert_request(request)
                request.url = self._client.format_url(request.url)

            return request

        def extract_data(pipeline_response):
            deserialized = self._deserialize("PolicyStatesQueryResults", pipeline_response)
            list_of_elem = deserialized.value
            if cls:
                list_of_elem = cls(list_of_elem)  # type: ignore
            return deserialized.odata_next_link or None, iter(list_of_elem)

        def get_next(next_link=None):
            request = prepare_request(next_link)

            pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
                request, stream=False, **kwargs
            )
            response = pipeline_response.http_response

            if response.status_code not in [200]:
                map_error(status_code=response.status_code, response=response, error_map=error_map)
                error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
                raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

            return pipeline_response

        return ItemPaged(get_next, extract_data)

    list_query_results_for_resource_group_level_policy_assignment.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults"
    }

    @distributed_trace
    def summarize_for_resource_group_level_policy_assignment(
        self,
        policy_states_summary_resource: Union[str, _models.PolicyStatesSummaryResourceType],
        subscription_id: str,
        resource_group_name: str,
        policy_assignment_name: str,
        query_options: Optional[_models.QueryOptions] = None,
        **kwargs: Any
    ) -> _models.SummarizeResults:
        """Summarizes policy states for the resource group level policy assignment.

        :param policy_states_summary_resource: 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. "latest" Required.
        :type policy_states_summary_resource: str or
         ~azure.mgmt.policyinsights.models.PolicyStatesSummaryResourceType
        :param subscription_id: Microsoft Azure subscription ID. Required.
        :type subscription_id: str
        :param resource_group_name: Resource group name. Required.
        :type resource_group_name: str
        :param policy_assignment_name: Policy assignment name. Required.
        :type policy_assignment_name: str
        :param query_options: Parameter group. Default value is None.
        :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions
        :keyword authorization_namespace: The namespace for Microsoft Authorization resource provider;
         only "Microsoft.Authorization" is allowed. Default value is "Microsoft.Authorization". Note
         that overriding this default value may result in unsupported behavior.
        :paramtype authorization_namespace: str
        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: SummarizeResults or the result of cls(response)
        :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults
        :raises ~azure.core.exceptions.HttpResponseError:
        """
        error_map = {
            401: ClientAuthenticationError,
            404: ResourceNotFoundError,
            409: ResourceExistsError,
            304: ResourceNotModifiedError,
        }
        error_map.update(kwargs.pop("error_map", {}) or {})

        _headers = kwargs.pop("headers", {}) or {}
        _params = case_insensitive_dict(kwargs.pop("params", {}) or {})

        authorization_namespace: Literal["Microsoft.Authorization"] = kwargs.pop(
            "authorization_namespace", "Microsoft.Authorization"
        )
        api_version: Literal["2019-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2019-10-01"))
        cls: ClsType[_models.SummarizeResults] = kwargs.pop("cls", None)

        _top = None
        _from_property = None
        _to = None
        _filter = None
        if query_options is not None:
            _filter = query_options.filter
            _from_property = query_options.from_property
            _to = query_options.to
            _top = query_options.top

        request = build_summarize_for_resource_group_level_policy_assignment_request(
            policy_states_summary_resource=policy_states_summary_resource,
            subscription_id=subscription_id,
            resource_group_name=resource_group_name,
            policy_assignment_name=policy_assignment_name,
            top=_top,
            from_property=_from_property,
            to=_to,
            filter=_filter,
            authorization_namespace=authorization_namespace,
            api_version=api_version,
            template_url=self.summarize_for_resource_group_level_policy_assignment.metadata["url"],
            headers=_headers,
            params=_params,
        )
        request = _convert_request(request)
        request.url = self._client.format_url(request.url)

        pipeline_response: PipelineResponse = self._client._pipeline.run(  # pylint: disable=protected-access
            request, stream=False, **kwargs
        )

        response = pipeline_response.http_response

        if response.status_code not in [200]:
            map_error(status_code=response.status_code, response=response, error_map=error_map)
            error = self._deserialize.failsafe_deserialize(_models.QueryFailure, pipeline_response)
            raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

        deserialized = self._deserialize("SummarizeResults", pipeline_response)

        if cls:
            return cls(pipeline_response, deserialized, {})

        return deserialized

    summarize_for_resource_group_level_policy_assignment.metadata = {
        "url": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize"
    }
