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

hub.exec.boto3.client.redshift.create_usage_limit
hub.exec.boto3.client.redshift.delete_usage_limit
hub.exec.boto3.client.redshift.describe_usage_limits
hub.exec.boto3.client.redshift.modify_usage_limit
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cluster_identifier: Text, feature_type: Text, limit_type: Text, amount: int, period: Text = None, breach_action: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a usage limit for a specified Amazon Redshift feature on a cluster. The usage limit is identified by the
    returned usage limit identifier.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_identifier(Text): The identifier of the cluster that you want to limit usage.
        feature_type(Text): The Amazon Redshift feature that you want to limit.
        limit_type(Text): The type of limit. Depending on the feature type, this can be based on a time duration or data
            size. If FeatureType is spectrum, then LimitType must be data-scanned. If FeatureType is
            concurrency-scaling, then LimitType must be time.
        amount(int): The limit amount. If time-based, this amount is in minutes. If data-based, this amount is in
            terabytes (TB). The value must be a positive number.
        period(Text, optional): The time period that the amount applies to. A weekly period begins on Sunday. The default is
            monthly. Defaults to None.
        breach_action(Text, optional): The action that Amazon Redshift takes when the limit is reached. The default is log. For more
            information about this parameter, see UsageLimit. 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.usage_limit.present:
                - name: value
                - cluster_identifier: value
                - feature_type: value
                - limit_type: value
                - amount: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.usage_limit.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_usage_limits(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_usage_limit(
                ctx,
                
                
                **{"ClusterIdentifier": cluster_identifier, "FeatureType": feature_type, "LimitType": limit_type, "Amount": amount, "Period": period, "BreachAction": breach_action, "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_usage_limits(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, usage_limit_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a usage limit from a cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        usage_limit_id(Text): The identifier of the usage limit to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

