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

hub.exec.boto3.client.waf.create_ip_set
hub.exec.boto3.client.waf.delete_ip_set
hub.exec.boto3.client.waf.get_ip_set
hub.exec.boto3.client.waf.list_ip_sets
hub.exec.boto3.client.waf.update_ip_set
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: 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.   Creates an IPSet, which you use to
    specify which web requests that you want to allow or block based on the IP addresses that the requests originate
    from. For example, if you're receiving a lot of requests from one or more individual IP addresses or one or more
    ranges of IP addresses and you want to block the requests, you can create an IPSet that contains those IP
    addresses and then configure AWS WAF to block the requests.  To create and configure an IPSet, perform the
    following steps:   Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of a
    CreateIPSet request.   Submit a CreateIPSet request.   Use GetChangeToken to get the change token that you
    provide in the ChangeToken parameter of an UpdateIPSet request.   Submit an UpdateIPSet request to specify the
    IP addresses that you want AWS WAF to watch for.   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 IPSet. You can't change Name after you create the IPSet.
        change_token(Text): The value returned by the most recent call to GetChangeToken.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, ip_set_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 an IPSet. You
    can't delete an IPSet if it's still used in any Rules or if it still includes any IP addresses. If you just want
    to remove an IPSet from a Rule, use UpdateRule. To permanently delete an IPSet from AWS WAF, perform the
    following steps:   Update the IPSet to remove IP address ranges, if any. For more information, see UpdateIPSet.
    Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of a DeleteIPSet
    request.   Submit a DeleteIPSet request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        ip_set_id(Text): The IPSetId of the IPSet that you want to delete. IPSetId is returned by CreateIPSet and by
            ListIPSets.
        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.ip_set.absent:
                - name: value
                - ip_set_id: value
                - change_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.waf.ip_set.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_ip_set(name)

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

