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

hub.exec.boto3.client.ec2.create_network_acl
hub.exec.boto3.client.ec2.delete_network_acl
hub.exec.boto3.client.ec2.describe_network_acls
resource = hub.tool.boto3.resource.create(ctx, "ec2", "NetworkAcl", name)
hub.tool.boto3.resource.exec(resource, create_entry, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, create_tags, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete_entry, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, replace_association, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, replace_entry, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, vpc_id: Text, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a network ACL in a VPC. Network ACLs provide an optional layer of security (in addition to security
    groups) for the instances in your VPC. For more information, see Network ACLs in the Amazon Virtual Private
    Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        vpc_id(Text): The ID of the VPC.
        tag_specifications(List, optional): The tags to assign to the network ACL. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.network_acl.present:
                - name: value
                - vpc_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.network_acl.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "NetworkAcl", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_network_acl(
                ctx,
                DryRun=ctx.test,
                
                **{"VpcId": vpc_id, "TagSpecifications": tag_specifications}
            )
            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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, network_acl_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified network ACL. You can't delete the ACL if it's associated with any subnets. You can't
    delete the default network ACL.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_acl_id(Text): The ID of the network ACL.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.network_acl.absent:
                - name: value
                - network_acl_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.network_acl.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "NetworkAcl", name)

    before = await hub.tool.boto3.resource.describe(resource)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.delete_network_acl(
                ctx,
                DryRun=ctx.test,
                
                **{"NetworkAclId": network_acl_id}
            )
            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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

