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

hub.exec.boto3.client.ec2.associate_client_vpn_target_network
hub.exec.boto3.client.ec2.describe_client_vpn_target_networks
hub.exec.boto3.client.ec2.disassociate_client_vpn_target_network
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_vpn_endpoint_id: Text, subnet_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a target network with a Client VPN endpoint. A target network is a subnet in a VPC. You can associate
    multiple subnets from the same VPC with a Client VPN endpoint. You can associate only one subnet in each
    Availability Zone. We recommend that you associate at least two subnets to provide Availability Zone redundancy.
    If you specified a VPC when you created the Client VPN endpoint or if you have previous subnet associations, the
    specified subnet must be in the same VPC. To specify a subnet that's in a different VPC, you must first modify
    the Client VPN endpoint (ModifyClientVpnEndpoint) and change the VPC that's associated with it.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_vpn_endpoint_id(Text): The ID of the Client VPN endpoint.
        subnet_id(Text): The ID of the subnet to associate with the Client VPN endpoint.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, client_vpn_endpoint_id: Text, association_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disassociates a target network from the specified Client VPN endpoint. When you disassociate the last target
    network from a Client VPN, the following happens:   The route that was automatically added for the VPC is
    deleted   All active client connections are terminated   New client connections are disallowed   The Client VPN
    endpoint's status changes to pending-associate

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_vpn_endpoint_id(Text): The ID of the Client VPN endpoint from which to disassociate the target network.
        association_id(Text): The ID of the target network association.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

