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

hub.exec.boto3.client.redshift.create_cluster_parameter_group
hub.exec.boto3.client.redshift.delete_cluster_parameter_group
hub.exec.boto3.client.redshift.describe_cluster_parameter_groups
hub.exec.boto3.client.redshift.modify_cluster_parameter_group
hub.exec.boto3.client.redshift.reset_cluster_parameter_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, parameter_group_name: Text, parameter_group_family: Text, description: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Redshift parameter group. Creating parameter groups is independent of creating clusters. You
    can associate a cluster with a parameter group when you create the cluster. You can also associate an existing
    cluster with a parameter group after the cluster is created by using ModifyCluster.  Parameters in the parameter
    group define specific behavior that applies to the databases you create on the cluster. For more information
    about parameters and parameter groups, go to Amazon Redshift Parameter Groups in the Amazon Redshift Cluster
    Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        parameter_group_name(Text): The name of the cluster parameter group. Constraints:   Must be 1 to 255 alphanumeric characters
            or hyphens   First character must be a letter.   Cannot end with a hyphen or contain two
            consecutive hyphens.   Must be unique withing your Amazon Web Services account.    This value is
            stored as a lower-case string.
        parameter_group_family(Text): The Amazon Redshift engine version to which the cluster parameter group applies. The cluster
            engine version determines the set of parameters. To get a list of valid parameter group family
            names, you can call DescribeClusterParameterGroups. By default, Amazon Redshift returns a list
            of all the parameter groups that are owned by your Amazon Web Services account, including the
            default parameter groups for each Amazon Redshift engine version. The parameter group family
            names associated with the default parameter groups provide you the valid values. For example, a
            valid family name is "redshift-1.0".
        description(Text): A description of the parameter 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_parameter_group.present:
                - name: value
                - parameter_group_name: value
                - parameter_group_family: value
                - description: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.cluster_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.redshift.describe_cluster_parameter_groups(name)

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

async def absent(hub, ctx, name: Text, parameter_group_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specified Amazon Redshift parameter group.  You cannot delete a parameter group if it is associated
    with a cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        parameter_group_name(Text): The name of the parameter group to be deleted. Constraints:   Must be the name of an existing
            cluster parameter group.   Cannot delete a default cluster parameter group.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

