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

hub.exec.boto3.client.cloudfront.create_key_group
hub.exec.boto3.client.cloudfront.delete_key_group
hub.exec.boto3.client.cloudfront.get_key_group
hub.exec.boto3.client.cloudfront.list_key_groups
hub.exec.boto3.client.cloudfront.update_key_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, key_group_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a key group that you can use with CloudFront signed URLs and signed cookies. To create a key group, you
    must specify at least one public key for the key group. After you create a key group, you can reference it from
    one or more cache behaviors. When you reference a key group in a cache behavior, CloudFront requires signed URLs
    or signed cookies for all requests that match the cache behavior. The URLs or cookies must be signed with a
    private key whose corresponding public key is in the key group. The signed URL or cookie contains information
    about which public key CloudFront should use to verify the signature. For more information, see Serving private
    content in the Amazon CloudFront Developer Guide.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_key_group(
                ctx,
                
                
                **{"KeyGroupConfig": key_group_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_key_group(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 a key group. You cannot delete a key group that is referenced in a cache behavior. First update your
    distributions to remove the key group from all cache behaviors, then delete the key group. To delete a key
    group, you must provide the key group’s identifier and version. To get these values, use ListKeyGroups followed
    by GetKeyGroup or GetKeyGroupConfig.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The identifier of the key group that you are deleting. To get the identifier, use ListKeyGroups.
        if_match(Text, optional): The version of the key group that you are deleting. The version is the key group’s ETag value.
            To get the ETag, use GetKeyGroup or GetKeyGroupConfig. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

