"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.cloudfront.create_origin_request_policy
hub.exec.boto3.client.cloudfront.delete_origin_request_policy
hub.exec.boto3.client.cloudfront.get_origin_request_policy
hub.exec.boto3.client.cloudfront.list_origin_request_policies
hub.exec.boto3.client.cloudfront.update_origin_request_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, origin_request_policy_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an origin request policy. After you create an origin request policy, you can attach it to one or more
    cache behaviors. When it’s attached to a cache behavior, the origin request policy determines the values that
    CloudFront includes in requests that it sends to the origin. Each request that CloudFront sends to the origin
    includes the following:   The request body and the URL path (without the domain name) from the viewer request.
    The headers that CloudFront automatically includes in every origin request, including Host, User-Agent, and
    X-Amz-Cf-Id.   All HTTP headers, cookies, and URL query strings that are specified in the cache policy or the
    origin request policy. These can include items from the viewer request and, in the case of headers, additional
    ones that are added by CloudFront.   CloudFront sends a request when it can’t find a valid object in its cache
    that matches the request. If you want to send values to the origin and also include them in the cache key, use
    CachePolicy. For more information about origin request policies, see Controlling origin requests in the Amazon
    CloudFront Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        origin_request_policy_config(Dict): An origin request policy configuration.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudfront.origin_request_policy.present:
                - name: value
                - origin_request_policy_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.origin_request_policy.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.cloudfront.get_origin_request_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_origin_request_policy(
                ctx,
                
                
                **{"OriginRequestPolicyConfig": origin_request_policy_config}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.cloudfront.get_origin_request_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, if_match: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an origin request policy. You cannot delete an origin request policy if it’s attached to any cache
    behaviors. First update your distributions to remove the origin request policy from all cache behaviors, then
    delete the origin request policy. To delete an origin request policy, you must provide the policy’s identifier
    and version. To get the identifier, you can use ListOriginRequestPolicies or GetOriginRequestPolicy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The unique identifier for the origin request policy that you are deleting. To get the
            identifier, you can use ListOriginRequestPolicies.
        if_match(Text, optional): The version of the origin request policy that you are deleting. The version is the origin
            request policy’s ETag value, which you can get using ListOriginRequestPolicies,
            GetOriginRequestPolicy, or GetOriginRequestPolicyConfig. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cloudfront.origin_request_policy.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.origin_request_policy.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.cloudfront.get_origin_request_policy(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.delete_origin_request_policy(
                ctx,
                
                
                **{"Id": id_, "IfMatch": if_match}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.cloudfront.get_origin_request_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

