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

hub.exec.boto3.client.ec2.create_client_vpn_route
hub.exec.boto3.client.ec2.delete_client_vpn_route
hub.exec.boto3.client.ec2.describe_client_vpn_routes
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_vpn_endpoint_id: Text, destination_cidr_block: Text, target_vpc_subnet_id: Text, description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds a route to a network to a Client VPN endpoint. Each Client VPN endpoint has a route table that describes
    the available destination network routes. Each route in the route table specifies the path for traﬃc to speciﬁc
    resources or networks.

    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 to which to add the route.
        destination_cidr_block(Text): The IPv4 address range, in CIDR notation, of the route destination. For example:   To add a
            route for Internet access, enter 0.0.0.0/0    To add a route for a peered VPC, enter the peered
            VPC's IPv4 CIDR range   To add a route for an on-premises network, enter the AWS Site-to-Site
            VPN connection's IPv4 CIDR range   To add a route for the local network, enter the client CIDR
            range.
        target_vpc_subnet_id(Text): The ID of the subnet through which you want to route traffic. The specified subnet must be an
            existing target network of the Client VPN endpoint. Alternatively, if you're adding a route for
            the local network, specify local.
        description(Text, optional): A brief description of the route. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, client_vpn_endpoint_id: Text, destination_cidr_block: Text, target_vpc_subnet_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a route from a Client VPN endpoint. You can only delete routes that you manually added using the
    CreateClientVpnRoute action. You cannot delete routes that were automatically added when associating a subnet.
    To remove routes that have been automatically added, disassociate the target subnet from the Client VPN
    endpoint.

    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 the route is to be deleted.
        target_vpc_subnet_id(Text, optional): The ID of the target subnet used by the route. Defaults to None.
        destination_cidr_block(Text): The IPv4 address range, in CIDR notation, of the route to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

