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

hub.exec.boto3.client.waf.delete_permission_policy
hub.exec.boto3.client.waf.get_permission_policy
hub.exec.boto3.client.waf.put_permission_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_arn: Text, policy: 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.   Attaches an IAM policy to the
    specified resource. The only supported use for this action is to share a RuleGroup across accounts. The
    PutPermissionPolicy is subject to the following restrictions:   You can attach only one policy with each
    PutPermissionPolicy request.   The policy must include an Effect, Action and Principal.     Effect must specify
    Allow.   The Action in the policy must be waf:UpdateWebACL, waf-regional:UpdateWebACL, waf:GetRuleGroup and waf-
    regional:GetRuleGroup . Any extra or wildcard actions in the policy will be rejected.   The policy cannot
    include a Resource parameter.   The ARN in the request must be a valid WAF RuleGroup ARN and the RuleGroup must
    exist in the same region.   The user making the request must be the owner of the RuleGroup.   Your policy must
    be composed using IAM Policy version 2012-10-17.   For more information, see IAM Policies.  An example of a
    valid policy parameter is shown in the Examples section below.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the RuleGroup to which you want to attach the policy.
        policy(Text): The policy to attach to the specified RuleGroup.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, resource_arn: 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 IAM policy
    from the specified RuleGroup. The user making the request must be the owner of the RuleGroup.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the RuleGroup from which you want to delete the policy. The
            user making the request must be the owner of the RuleGroup.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

