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

hub.exec.boto3.client.waf.create_rule_group
hub.exec.boto3.client.waf.delete_rule_group
hub.exec.boto3.client.waf.get_rule_group
hub.exec.boto3.client.waf.list_rule_groups
hub.exec.boto3.client.waf.update_rule_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, metric_name: Text, change_token: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This is AWS WAF Classic documentation. For more information, see AWS WAF Classic in the developer guide.  For
    the latest version of AWS WAF, use the AWS WAFV2 API and see the AWS WAF Developer Guide. With the latest
    version, AWS WAF has a single set of endpoints for regional and global use.   Creates a RuleGroup. A rule group
    is a collection of predefined rules that you add to a web ACL. You use UpdateRuleGroup to add rules to the rule
    group. Rule groups are subject to the following limits:   Three rule groups per account. You can request an
    increase to this limit by contacting customer support.   One rule group per web ACL.   Ten rules per rule group.
    For more information about how to use the AWS WAF API to allow or block HTTP requests, see the AWS WAF Developer
    Guide.

    Args:
        name(Text): A friendly name or description of the RuleGroup. You can't change Name after you create a
            RuleGroup.
        metric_name(Text): A friendly name or description for the metrics for this RuleGroup. The name can contain only
            alphanumeric characters (A-Z, a-z, 0-9), with maximum length 128 and minimum length one. It
            can't contain whitespace or metric names reserved for AWS WAF, including "All" and
            "Default_Action." You can't change the name of the metric after you create the RuleGroup.
        change_token(Text): The value returned by the most recent call to GetChangeToken.
        tags(List, optional): . Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.waf.rule_group.present:
                - name: value
                - metric_name: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf.rule_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.waf.get_rule_group(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.waf.create_rule_group(
                ctx,
                
                
                **{"Name": name, "MetricName": metric_name, "ChangeToken": change_token, "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.waf.get_rule_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rule_group_id: Text, change_token: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This is AWS WAF Classic documentation. For more information, see AWS WAF Classic in the developer guide.  For
    the latest version of AWS WAF, use the AWS WAFV2 API and see the AWS WAF Developer Guide. With the latest
    version, AWS WAF has a single set of endpoints for regional and global use.   Permanently deletes a RuleGroup.
    You can't delete a RuleGroup if it's still used in any WebACL objects or if it still includes any rules. If you
    just want to remove a RuleGroup from a WebACL, use UpdateWebACL. To permanently delete a RuleGroup from AWS WAF,
    perform the following steps:   Update the RuleGroup to remove rules, if any. For more information, see
    UpdateRuleGroup.   Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of a
    DeleteRuleGroup request.   Submit a DeleteRuleGroup request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_group_id(Text): The RuleGroupId of the RuleGroup that you want to delete. RuleGroupId is returned by
            CreateRuleGroup and by ListRuleGroups.
        change_token(Text): The value returned by the most recent call to GetChangeToken.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.waf.rule_group.absent:
                - name: value
                - rule_group_id: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf.rule_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.waf.get_rule_group(name)

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

