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

hub.exec.boto3.client.elasticache.create_cache_parameter_group
hub.exec.boto3.client.elasticache.delete_cache_parameter_group
hub.exec.boto3.client.elasticache.describe_cache_parameter_groups
hub.exec.boto3.client.elasticache.modify_cache_parameter_group
hub.exec.boto3.client.elasticache.reset_cache_parameter_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cache_parameter_group_name: Text, cache_parameter_group_family: Text, description: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Amazon ElastiCache cache parameter group. An ElastiCache cache parameter group is a collection of
    parameters and their values that are applied to all of the nodes in any cluster or replication group using the
    CacheParameterGroup. A newly created CacheParameterGroup is an exact duplicate of the default parameter group
    for the CacheParameterGroupFamily. To customize the newly created CacheParameterGroup you can change the values
    of specific parameters. For more information, see:    ModifyCacheParameterGroup in the ElastiCache API
    Reference.    Parameters and Parameter Groups in the ElastiCache User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cache_parameter_group_name(Text): A user-specified name for the cache parameter group.
        cache_parameter_group_family(Text): The name of the cache parameter group family that the cache parameter group can be used with.
            Valid values are: memcached1.4 | memcached1.5 | memcached1.6 | redis2.6 | redis2.8 | redis3.2 |
            redis4.0 | redis5.0 | redis6.x |.
        description(Text): A user-specified description for the cache parameter group.
        tags(List, optional): A list of tags to be added to this resource. A tag is a key-value pair. A tag key must be
            accompanied by a tag value, although null is accepted. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.elasticache.cache_parameter_group.present:
                - name: value
                - cache_parameter_group_name: value
                - cache_parameter_group_family: value
                - description: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elasticache.cache_parameter_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.elasticache.describe_cache_parameter_groups(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elasticache.create_cache_parameter_group(
                ctx,
                
                
                **{"CacheParameterGroupName": cache_parameter_group_name, "CacheParameterGroupFamily": cache_parameter_group_family, "Description": description, "Tags": tags}
            )
            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.elasticache.describe_cache_parameter_groups(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cache_parameter_group_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified cache parameter group. You cannot delete a cache parameter group if it is associated with
    any cache clusters. You cannot delete the default cache parameter groups in your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cache_parameter_group_name(Text): The name of the cache parameter group to delete.  The specified cache security group must not be
            associated with any clusters.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.elasticache.cache_parameter_group.absent:
                - name: value
                - cache_parameter_group_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elasticache.cache_parameter_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.elasticache.describe_cache_parameter_groups(name)

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

