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

hub.exec.boto3.client.redshift.create_snapshot_copy_grant
hub.exec.boto3.client.redshift.delete_snapshot_copy_grant
hub.exec.boto3.client.redshift.describe_snapshot_copy_grants
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, snapshot_copy_grant_name: Text, kms_key_id: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a snapshot copy grant that permits Amazon Redshift to use a customer master key (CMK) from Key
    Management Service (KMS) to encrypt copied snapshots in a destination region.  For more information about
    managing snapshot copy grants, go to Amazon Redshift Database Encryption in the Amazon Redshift Cluster
    Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_copy_grant_name(Text): The name of the snapshot copy grant. This name must be unique in the region for the Amazon Web
            Services account. Constraints:   Must contain from 1 to 63 alphanumeric characters or hyphens.
            Alphabetic characters must be lowercase.   First character must be a letter.   Cannot end with a
            hyphen or contain two consecutive hyphens.   Must be unique for all clusters within an Amazon
            Web Services account.
        kms_key_id(Text, optional): The unique identifier of the customer master key (CMK) to which to grant Amazon Redshift
            permission. If no key is specified, the default key is used. 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.snapshot_copy_grant.present:
                - name: value
                - snapshot_copy_grant_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.snapshot_copy_grant.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_snapshot_copy_grants(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_snapshot_copy_grant(
                ctx,
                
                
                **{"SnapshotCopyGrantName": snapshot_copy_grant_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.redshift.describe_snapshot_copy_grants(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, snapshot_copy_grant_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified snapshot copy grant.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        snapshot_copy_grant_name(Text): The name of the snapshot copy grant to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

