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

hub.exec.boto3.client.ec2.create_nat_gateway
hub.exec.boto3.client.ec2.delete_nat_gateway
hub.exec.boto3.client.ec2.describe_nat_gateways
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subnet_id: Text, allocation_id: Text = None, tag_specifications: List = None, connectivity_type: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a NAT gateway in the specified subnet. This action creates a network interface in the specified subnet
    with a private IP address from the IP address range of the subnet. You can create either a public NAT gateway or
    a private NAT gateway. With a public NAT gateway, internet-bound traffic from a private subnet can be routed to
    the NAT gateway, so that instances in a private subnet can connect to the internet. With a private NAT gateway,
    private communication is routed across VPCs and on-premises networks through a transit gateway or virtual
    private gateway. Common use cases include running large workloads behind a small pool of allowlisted IPv4
    addresses, preserving private IPv4 addresses, and communicating between overlapping networks. For more
    information, see NAT gateways in the Amazon Virtual Private Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        allocation_id(Text, optional): [Public NAT gateways only] The allocation ID of an Elastic IP address to associate with the NAT
            gateway. You cannot specify an Elastic IP address with a private NAT gateway. If the Elastic IP
            address is associated with another resource, you must first disassociate it. Defaults to None.
        subnet_id(Text): The subnet in which to create the NAT gateway.
        tag_specifications(List, optional): The tags to assign to the NAT gateway. Defaults to None.
        connectivity_type(Text, optional): Indicates whether the NAT gateway supports public or private connectivity. The default is public
            connectivity. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_nat_gateway(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"AllocationId": allocation_id, "SubnetId": subnet_id, "TagSpecifications": tag_specifications, "ConnectivityType": connectivity_type}
            )
            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.ec2.describe_nat_gateways(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, nat_gateway_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified NAT gateway. Deleting a public NAT gateway disassociates its Elastic IP address, but does
    not release the address from your account. Deleting a NAT gateway does not delete any NAT gateway routes in your
    route tables.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        nat_gateway_id(Text): The ID of the NAT gateway.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

