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

hub.exec.boto3.client.redshift.copy_cluster_snapshot
hub.exec.boto3.client.redshift.create_cluster_snapshot
hub.exec.boto3.client.redshift.delete_cluster_snapshot
hub.exec.boto3.client.redshift.describe_cluster_snapshots
hub.exec.boto3.client.redshift.modify_cluster_snapshot
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, snapshot_identifier: Text, cluster_identifier: Text, manual_snapshot_retention_period: int = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a manual snapshot of the specified cluster. The cluster must be in the available state.   For more
    information about working with snapshots, go to Amazon Redshift Snapshots in the Amazon Redshift Cluster
    Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_identifier(Text): A unique identifier for the snapshot that you are requesting. This identifier must be unique for
            all snapshots within the Amazon Web Services account. Constraints:   Cannot be null, empty, or
            blank   Must contain from 1 to 255 alphanumeric characters or hyphens   First character must be
            a letter   Cannot end with a hyphen or contain two consecutive hyphens   Example: my-snapshot-id.
        cluster_identifier(Text): The cluster identifier for which you want a snapshot.
        manual_snapshot_retention_period(int, optional): The number of days that a manual snapshot is retained. If the value is -1, the manual snapshot
            is retained indefinitely.  The value must be either -1 or an integer between 1 and 3,653. The
            default value is -1. Defaults to None.
        tags(List, optional): A list of tag instances. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.cluster_snapshot.present:
                - name: value
                - snapshot_identifier: value
                - cluster_identifier: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.cluster_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.redshift.describe_cluster_snapshots(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_cluster_snapshot(
                ctx,
                
                
                **{"SnapshotIdentifier": snapshot_identifier, "ClusterIdentifier": cluster_identifier, "ManualSnapshotRetentionPeriod": manual_snapshot_retention_period, "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.redshift.describe_cluster_snapshots(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, snapshot_identifier: Text, snapshot_cluster_identifier: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified manual snapshot. The snapshot must be in the available state, with no other users
    authorized to access the snapshot.  Unlike automated snapshots, manual snapshots are retained even after you
    delete your cluster. Amazon Redshift does not delete your manual snapshots. You must delete manual snapshot
    explicitly to avoid getting charged. If other accounts are authorized to access the snapshot, you must revoke
    all of the authorizations before you can delete the snapshot.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_identifier(Text): The unique identifier of the manual snapshot to be deleted. Constraints: Must be the name of an
            existing snapshot that is in the available, failed, or cancelled state.
        snapshot_cluster_identifier(Text, optional): The unique identifier of the cluster the snapshot was created from. This parameter is required
            if your IAM user has a policy containing a snapshot resource element that specifies anything
            other than * for the cluster name. Constraints: Must be the name of valid cluster. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.redshift.cluster_snapshot.absent:
                - name: value
                - snapshot_identifier: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.cluster_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.redshift.describe_cluster_snapshots(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.delete_cluster_snapshot(
                ctx,
                
                
                **{"SnapshotIdentifier": snapshot_identifier, "SnapshotClusterIdentifier": snapshot_cluster_identifier}
            )
            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.redshift.describe_cluster_snapshots(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

