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

hub.exec.boto3.client.redshift.create_tags
hub.exec.boto3.client.redshift.delete_tags
hub.exec.boto3.client.redshift.describe_tags
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_name: Text, tags: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds tags to a cluster. A resource can have up to 50 tags. If you try to create more than 50 tags for a
    resource, you will receive an error and the attempt will fail. If you specify a key that already exists for the
    resource, the value for that key will be updated with the new value.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_name(Text): The Amazon Resource Name (ARN) to which you want to add the tag or tags. For example,
            arn:aws:redshift:us-east-2:123456789:cluster:t1.
        tags(List): One or more name/value pairs to add as tags to the specified resource. Each tag name is passed
            in with the parameter Key and the corresponding value is passed in with the parameter Value. The
            Key and Value parameters are separated by a comma (,). Separate multiple tags with a space. For
            example, --tags "Key"="owner","Value"="admin" "Key"="environment","Value"="test"
            "Key"="version","Value"="1.0".

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.tag.present:
                - name: value
                - resource_name: value
                - tags: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.tag.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_tags(name)

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

async def absent(hub, ctx, name: Text, resource_name: Text, tag_keys: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes tags from a resource. You must provide the ARN of the resource from which you want to delete the tag or
    tags.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_name(Text): The Amazon Resource Name (ARN) from which you want to remove the tag or tags. For example,
            arn:aws:redshift:us-east-2:123456789:cluster:t1.
        tag_keys(List): The tag key that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

