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

hub.exec.boto3.client.waf_regional.create_rule
hub.exec.boto3.client.waf_regional.delete_rule
hub.exec.boto3.client.waf_regional.get_rule
hub.exec.boto3.client.waf_regional.list_rules
hub.exec.boto3.client.waf_regional.update_rule
"""



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 Rule, which contains the
    IPSet objects, ByteMatchSet objects, and other predicates that identify the requests that you want to block. If
    you add more than one predicate to a Rule, a request must match all of the specifications to be allowed or
    blocked. For example, suppose that you add the following to a Rule:   An IPSet that matches the IP address
    192.0.2.44/32    A ByteMatchSet that matches BadBot in the User-Agent header   You then add the Rule to a WebACL
    and specify that you want to blocks requests that satisfy the Rule. For a request to be blocked, it must come
    from the IP address 192.0.2.44 and the User-Agent header in the request must contain the value BadBot. To create
    and configure a Rule, perform the following steps:   Create and update the predicates that you want to include
    in the Rule. For more information, see CreateByteMatchSet, CreateIPSet, and CreateSqlInjectionMatchSet.   Use
    GetChangeToken to get the change token that you provide in the ChangeToken parameter of a CreateRule request.
    Submit a CreateRule request.   Use GetChangeToken to get the change token that you provide in the ChangeToken
    parameter of an UpdateRule request.   Submit an UpdateRule request to specify the predicates that you want to
    include in the Rule.   Create and update a WebACL that contains the Rule. For more information, see
    CreateWebACL.   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 Rule. You can't change the name of a Rule after you create
            it.
        metric_name(Text): A friendly name or description for the metrics for this Rule. 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 Rule.
        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_regional.rule.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_regional.rule.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_regional.get_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.waf_regional.create_rule(
                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_regional.get_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rule_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 Rule. You
    can't delete a Rule if it's still used in any WebACL objects or if it still includes any predicates, such as
    ByteMatchSet objects. If you just want to remove a Rule from a WebACL, use UpdateWebACL. To permanently delete a
    Rule from AWS WAF, perform the following steps:   Update the Rule to remove predicates, if any. For more
    information, see UpdateRule.   Use GetChangeToken to get the change token that you provide in the ChangeToken
    parameter of a DeleteRule request.   Submit a DeleteRule request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_id(Text): The RuleId of the Rule that you want to delete. RuleId is returned by CreateRule and by
            ListRules.
        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_regional.rule.absent:
                - name: value
                - rule_id: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf_regional.rule.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_regional.get_rule(name)

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

