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

hub.exec.boto3.client.ec2.attach_network_interface
hub.exec.boto3.client.ec2.create_network_interface
hub.exec.boto3.client.ec2.delete_network_interface
hub.exec.boto3.client.ec2.describe_network_interfaces
hub.exec.boto3.client.ec2.detach_network_interface
resource = hub.tool.boto3.resource.create(ctx, "ec2", "NetworkInterface", name)
hub.tool.boto3.resource.exec(resource, assign_private_ip_addresses, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, attach, *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, describe_attribute, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, detach, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, modify_attribute, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, reset_attribute, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, unassign_private_ip_addresses, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subnet_id: Text, description: Text = None, groups: List = None, ipv6_address_count: int = None, ipv6_addresses: List = None, private_ip_address: Text = None, private_ip_addresses: List = None, secondary_private_ip_address_count: int = None, ipv4_prefixes: List = None, ipv4_prefix_count: int = None, ipv6_prefixes: List = None, ipv6_prefix_count: int = None, interface_type: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a network interface in the specified subnet. For more information about network interfaces, see Elastic
    Network Interfaces in the Amazon Virtual Private Cloud User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        description(Text, optional): A description for the network interface. Defaults to None.
        groups(List, optional): The IDs of one or more security groups. Defaults to None.
        ipv6_address_count(int, optional): The number of IPv6 addresses to assign to a network interface. Amazon EC2 automatically selects
            the IPv6 addresses from the subnet range. You can't use this option if specifying specific IPv6
            addresses. If your subnet has the AssignIpv6AddressOnCreation attribute set to true, you can
            specify 0 to override this setting. Defaults to None.
        ipv6_addresses(List, optional): One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet. You can't use
            this option if you're specifying a number of IPv6 addresses. Defaults to None.
        private_ip_address(Text, optional): The primary private IPv4 address of the network interface. If you don't specify an IPv4 address,
            Amazon EC2 selects one for you from the subnet's IPv4 CIDR range. If you specify an IP address,
            you cannot indicate any IP addresses specified in privateIpAddresses as primary (only one IP
            address can be designated as primary). Defaults to None.
        private_ip_addresses(List, optional): One or more private IPv4 addresses. Defaults to None.
        secondary_private_ip_address_count(int, optional): The number of secondary private IPv4 addresses to assign to a network interface. When you
            specify a number of secondary IPv4 addresses, Amazon EC2 selects these IP addresses within the
            subnet's IPv4 CIDR range. You can't specify this option and specify more than one private IP
            address using privateIpAddresses. The number of IP addresses you can assign to a network
            interface varies by instance type. For more information, see IP Addresses Per ENI Per Instance
            Type in the Amazon Virtual Private Cloud User Guide. Defaults to None.
        ipv4_prefixes(List, optional): One or moreIPv4 Prefix Delegation prefixes assigned to the network interface. You cannot use
            this option if you use the Ipv4PrefixCount option. Defaults to None.
        ipv4_prefix_count(int, optional): The number of IPv4 Prefix Delegation prefixes that AWS automatically assigns to the network
            interface. You cannot use this option if you use the Ipv4 Prefixes option. Defaults to None.
        ipv6_prefixes(List, optional): One or moreIPv6 Prefix Delegation prefixes assigned to the network interface. You cannot use
            this option if you use the Ipv6PrefixCount option. Defaults to None.
        ipv6_prefix_count(int, optional): The number of IPv6 Prefix Delegation prefixes that AWS automatically assigns to the network
            interface. You cannot use this option if you use the Ipv6Prefixes option. Defaults to None.
        interface_type(Text, optional): Indicates the type of network interface. To create an Elastic Fabric Adapter (EFA), specify efa.
            For more information, see  Elastic Fabric Adapter in the Amazon Elastic Compute Cloud User
            Guide. To create a trunk network interface, specify efa. For more information, see  Network
            interface trunking in the Amazon Elastic Compute Cloud User Guide. Defaults to None.
        subnet_id(Text): The ID of the subnet to associate with the network interface.
        tag_specifications(List, optional): The tags to apply to the new network interface. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.network_interface.present:
                - name: value
                - subnet_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.network_interface.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", "NetworkInterface", 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_interface(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"Description": description, "Groups": groups, "Ipv6AddressCount": ipv6_address_count, "Ipv6Addresses": ipv6_addresses, "PrivateIpAddress": private_ip_address, "PrivateIpAddresses": private_ip_addresses, "SecondaryPrivateIpAddressCount": secondary_private_ip_address_count, "Ipv4Prefixes": ipv4_prefixes, "Ipv4PrefixCount": ipv4_prefix_count, "Ipv6Prefixes": ipv6_prefixes, "Ipv6PrefixCount": ipv6_prefix_count, "InterfaceType": interface_type, "SubnetId": subnet_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_interface_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified network interface. You must detach the network interface before you can delete it.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.network_interface.absent:
                - name: value
                - network_interface_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.network_interface.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", "NetworkInterface", 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_interface(
                ctx,
                DryRun=ctx.test,
                
                **{"NetworkInterfaceId": network_interface_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

