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

hub.exec.boto3.client.waf.create_web_acl
hub.exec.boto3.client.waf.delete_web_acl
hub.exec.boto3.client.waf.get_web_acl
hub.exec.boto3.client.waf.list_web_acls
hub.exec.boto3.client.waf.update_web_acl
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, metric_name: Text, default_action: Dict, 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 WebACL, which contains
    the Rules that identify the CloudFront web requests that you want to allow, block, or count. AWS WAF evaluates
    Rules in order based on the value of Priority for each Rule. You also specify a default action, either ALLOW or
    BLOCK. If a web request doesn't match any of the Rules in a WebACL, AWS WAF responds to the request with the
    default action.  To create and configure a WebACL, perform the following steps:   Create and update the
    ByteMatchSet objects and other predicates that you want to include in Rules. For more information, see
    CreateByteMatchSet, UpdateByteMatchSet, CreateIPSet, UpdateIPSet, CreateSqlInjectionMatchSet, and
    UpdateSqlInjectionMatchSet.   Create and update the Rules that you want to include in the WebACL. For more
    information, see CreateRule and UpdateRule.   Use GetChangeToken to get the change token that you provide in the
    ChangeToken parameter of a CreateWebACL request.   Submit a CreateWebACL request.   Use GetChangeToken to get
    the change token that you provide in the ChangeToken parameter of an UpdateWebACL request.   Submit an
    UpdateWebACL request to specify the Rules that you want to include in the WebACL, to specify the default action,
    and to associate the WebACL with a CloudFront distribution.   For more information about how to use the AWS WAF
    API, see the AWS WAF Developer Guide.

    Args:
        name(Text): A friendly name or description of the WebACL. You can't change Name after you create the WebACL.
        metric_name(Text): A friendly name or description for the metrics for this WebACL.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 MetricName after you create the WebACL.
        default_action(Dict): The action that you want AWS WAF to take when a request doesn't match the criteria specified in
            any of the Rule objects that are associated with the WebACL.
        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.web_acl.present:
                - name: value
                - metric_name: value
                - default_action: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf.web_acl.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_web_acl(name)

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

async def absent(hub, ctx, name: Text, web_acl_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 WebACL. You
    can't delete a WebACL if it still contains any Rules. To delete a WebACL, perform the following steps:   Update
    the WebACL to remove Rules, if any. For more information, see UpdateWebACL.   Use GetChangeToken to get the
    change token that you provide in the ChangeToken parameter of a DeleteWebACL request.   Submit a DeleteWebACL
    request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        web_acl_id(Text): The WebACLId of the WebACL that you want to delete. WebACLId is returned by CreateWebACL and by
            ListWebACLs.
        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.web_acl.absent:
                - name: value
                - web_acl_id: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf.web_acl.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_web_acl(name)

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

