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

hub.exec.boto3.client.network_firewall.delete_resource_policy
hub.exec.boto3.client.network_firewall.describe_resource_policy
hub.exec.boto3.client.network_firewall.put_resource_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**
    
    Creates or updates an AWS Identity and Access Management policy for your rule group or firewall policy. Use this
    to share rule groups and firewall policies between accounts. This operation works in conjunction with the AWS
    Resource Access Manager (RAM) service to manage resource sharing for Network Firewall.  Use this operation to
    create or update a resource policy for your rule group or firewall policy. In the policy, you specify the
    accounts that you want to share the resource with and the operations that you want the accounts to be able to
    perform.  When you add an account in the resource policy, you then run the following Resource Access Manager
    (RAM) operations to access and accept the shared rule group or firewall policy.     GetResourceShareInvitations
    - Returns the Amazon Resource Names (ARNs) of the resource share invitations.     AcceptResourceShareInvitation
    - Accepts the share invitation for a specified resource share.    For additional information about resource
    sharing using RAM, see AWS Resource Access Manager User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the account that you want to share rule groups and firewall
            policies with.
        policy(Text): The AWS Identity and Access Management policy statement that lists the accounts that you want to
            share your rule group or firewall policy with and the operations that you want the accounts to
            be able to perform.  For a rule group resource, you can specify the following operations in the
            Actions section of the statement:   network-firewall:CreateFirewallPolicy   network-
            firewall:UpdateFirewallPolicy   network-firewall:ListRuleGroups   For a firewall policy
            resource, you can specify the following operations in the Actions section of the statement:
            network-firewall:CreateFirewall   network-firewall:UpdateFirewall   network-
            firewall:AssociateFirewallPolicy   network-firewall:ListFirewallPolicies   In the Resource
            section of the statement, you specify the ARNs for the rule groups and firewall policies that
            you want to share with the account that you specified in Arn.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.network_firewall.put_resource_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.network_firewall.describe_resource_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**
    
    Deletes a resource policy that you created in a PutResourcePolicy request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the rule group or firewall policy whose resource policy you
            want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

