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

hub.exec.boto3.client.redshift.create_cluster_security_group
hub.exec.boto3.client.redshift.delete_cluster_security_group
hub.exec.boto3.client.redshift.describe_cluster_security_groups
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cluster_security_group_name: Text, description: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Amazon Redshift security group. You use security groups to control access to non-VPC clusters.
    For information about managing security groups, go to Amazon Redshift Cluster Security Groups in the Amazon
    Redshift Cluster Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_security_group_name(Text): The name for the security group. Amazon Redshift stores the value as a lowercase string.
            Constraints:   Must contain no more than 255 alphanumeric characters or hyphens.   Must not be
            "Default".   Must be unique for all security groups that are created by your Amazon Web Services
            account.   Example: examplesecuritygroup.
        description(Text): A description for the security group.
        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_security_group.present:
                - name: value
                - cluster_security_group_name: value
                - description: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.cluster_security_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.redshift.describe_cluster_security_groups(name)

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

async def absent(hub, ctx, name: Text, cluster_security_group_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon Redshift security group.  You cannot delete a security group that is associated with any
    clusters. You cannot delete the default security group.   For information about managing security groups, go to
    Amazon Redshift Cluster Security Groups in the Amazon Redshift Cluster Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_security_group_name(Text): The name of the cluster security group to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

