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

hub.exec.boto3.client.cloudfront.create_cloud_front_origin_access_identity
hub.exec.boto3.client.cloudfront.delete_cloud_front_origin_access_identity
hub.exec.boto3.client.cloudfront.get_cloud_front_origin_access_identity
hub.exec.boto3.client.cloudfront.list_cloud_front_origin_access_identities
hub.exec.boto3.client.cloudfront.update_cloud_front_origin_access_identity
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cloud_front_origin_access_identity_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new origin access identity. If you're using Amazon S3 for your origin, you can use an origin access
    identity to require users to access your content using a CloudFront URL instead of the Amazon S3 URL. For more
    information about how to use origin access identities, see Serving Private Content through CloudFront in the
    Amazon CloudFront Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cloud_front_origin_access_identity_config(Dict): The current configuration information for the identity.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudfront.cloud_front_origin_access_identity.present:
                - name: value
                - cloud_front_origin_access_identity_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.cloud_front_origin_access_identity.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_cloud_front_origin_access_identity(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_cloud_front_origin_access_identity(
                ctx,
                
                
                **{"CloudFrontOriginAccessIdentityConfig": cloud_front_origin_access_identity_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_cloud_front_origin_access_identity(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**
    
    Delete an origin access identity.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The origin access identity's ID.
        if_match(Text, optional): The value of the ETag header you received from a previous GET or PUT request. For example:
            E2QWRUHAPOMQZL. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cloudfront.cloud_front_origin_access_identity.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.cloud_front_origin_access_identity.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_cloud_front_origin_access_identity(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.delete_cloud_front_origin_access_identity(
                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_cloud_front_origin_access_identity(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

