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

hub.exec.boto3.client.cloudfront.create_public_key
hub.exec.boto3.client.cloudfront.delete_public_key
hub.exec.boto3.client.cloudfront.get_public_key
hub.exec.boto3.client.cloudfront.list_public_keys
hub.exec.boto3.client.cloudfront.update_public_key
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, public_key_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Uploads a public key to CloudFront that you can use with signed URLs and signed cookies, or with field-level
    encryption.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        public_key_config(Dict): A CloudFront public key configuration.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_public_key(
                ctx,
                
                
                **{"PublicKeyConfig": public_key_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_public_key(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**
    
    Remove a public key you previously added to CloudFront.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the public key you want to remove from CloudFront.
        if_match(Text, optional): The value of the ETag header that you received when retrieving the public key identity to
            delete. For example: E2QWRUHAPOMQZL. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

