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

hub.exec.boto3.client.ec2.create_vpn_connection
hub.exec.boto3.client.ec2.delete_vpn_connection
hub.exec.boto3.client.ec2.describe_vpn_connections
hub.exec.boto3.client.ec2.modify_vpn_connection
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, customer_gateway_id: Text, type_: Text, vpn_gateway_id: Text = None, transit_gateway_id: Text = None, options: Dict = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a VPN connection between an existing virtual private gateway or transit gateway and a customer gateway.
    The supported connection type is ipsec.1. The response includes information that you need to give to your
    network administrator to configure your customer gateway.  We strongly recommend that you use HTTPS when calling
    this operation because the response contains sensitive cryptographic information for configuring your customer
    gateway device.  If you decide to shut down your VPN connection for any reason and later create a new VPN
    connection, you must reconfigure your customer gateway with the new information returned from this call. This is
    an idempotent operation. If you perform the operation more than once, Amazon EC2 doesn't return an error. For
    more information, see AWS Site-to-Site VPN in the AWS Site-to-Site VPN User Guide.

    Args:
        name(Text): The name of the state.
        customer_gateway_id(Text): The ID of the customer gateway.
        type_(Text): The type of VPN connection (ipsec.1).
        vpn_gateway_id(Text, optional): The ID of the virtual private gateway. If you specify a virtual private gateway, you cannot
            specify a transit gateway. Defaults to None.
        transit_gateway_id(Text, optional): The ID of the transit gateway. If you specify a transit gateway, you cannot specify a virtual
            private gateway. Defaults to None.
        options(Dict, optional): The options for the VPN connection. Defaults to None.
        tag_specifications(List, optional): The tags to apply to the VPN connection. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.vpn_connection.present:
                - name: value
                - customer_gateway_id: value
                - type_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)

    
    before = await hub.exec.boto3.client.ec2.describe_vpn_connections(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_vpn_connection(
                ctx,
                DryRun=ctx.test,
                
                **{"CustomerGatewayId": customer_gateway_id, "Type": type_, "VpnGatewayId": vpn_gateway_id, "TransitGatewayId": transit_gateway_id, "Options": options, "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.exec.boto3.client.ec2.describe_vpn_connections(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, vpn_connection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified VPN connection. If you're deleting the VPC and its associated components, we recommend
    that you detach the virtual private gateway from the VPC and delete the VPC before deleting the VPN connection.
    If you believe that the tunnel credentials for your VPN connection have been compromised, you can delete the VPN
    connection and create a new one that has new keys, without needing to delete the VPC or virtual private gateway.
    If you create a new VPN connection, you must reconfigure the customer gateway device using the new configuration
    information returned with the new VPN connection ID. For certificate-based authentication, delete all AWS
    Certificate Manager (ACM) private certificates used for the AWS-side tunnel endpoints for the VPN connection
    before deleting the VPN connection.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        vpn_connection_id(Text): The ID of the VPN connection.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

