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

hub.exec.boto3.client.elasticache.copy_snapshot
hub.exec.boto3.client.elasticache.create_snapshot
hub.exec.boto3.client.elasticache.delete_snapshot
hub.exec.boto3.client.elasticache.describe_snapshots
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, snapshot_name: Text, replication_group_id: Text = None, cache_cluster_id: Text = None, kms_key_id: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a copy of an entire cluster or replication group at a specific moment in time.  This operation is valid
    for Redis only.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        replication_group_id(Text, optional): The identifier of an existing replication group. The snapshot is created from this replication
            group. Defaults to None.
        cache_cluster_id(Text, optional): The identifier of an existing cluster. The snapshot is created from this cluster. Defaults to None.
        snapshot_name(Text): A name for the snapshot being created.
        kms_key_id(Text, optional): The ID of the KMS key used to encrypt the snapshot. Defaults to None.
        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.snapshot.present:
                - name: value
                - snapshot_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elasticache.snapshot.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_snapshots(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elasticache.create_snapshot(
                ctx,
                
                
                **{"ReplicationGroupId": replication_group_id, "CacheClusterId": cache_cluster_id, "SnapshotName": snapshot_name, "KmsKeyId": kms_key_id, "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_snapshots(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, snapshot_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing snapshot. When you receive a successful response from this operation, ElastiCache
    immediately begins deleting the snapshot; you cannot cancel or revert this operation.  This operation is valid
    for Redis only.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_name(Text): The name of the snapshot to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

