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

hub.exec.boto3.client.ec2.create_route
hub.exec.boto3.client.ec2.delete_route
hub.exec.boto3.client.ec2.replace_route
resource = hub.tool.boto3.resource.create(ctx, "ec2", "Route", name)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, replace, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, route_table_id: Text, destination_cidr_block: Text = None, destination_ipv6_cidr_block: Text = None, destination_prefix_list_id: Text = None, vpc_endpoint_id: Text = None, egress_only_internet_gateway_id: Text = None, gateway_id: Text = None, instance_id: Text = None, nat_gateway_id: Text = None, transit_gateway_id: Text = None, local_gateway_id: Text = None, carrier_gateway_id: Text = None, network_interface_id: Text = None, vpc_peering_connection_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a route in a route table within a VPC. You must specify one of the following targets: internet gateway
    or virtual private gateway, NAT instance, NAT gateway, VPC peering connection, network interface, egress-only
    internet gateway, or transit gateway. When determining how to route traffic, we use the route with the most
    specific match. For example, traffic is destined for the IPv4 address 192.0.2.3, and the route table includes
    the following two IPv4 routes:    192.0.2.0/24 (goes to some target A)    192.0.2.0/28 (goes to some target B)
    Both routes apply to the traffic destined for 192.0.2.3. However, the second route in the list covers a smaller
    number of IP addresses and is therefore more specific, so we use that route to determine where to target the
    traffic. For more information about route tables, see Route tables in the Amazon Virtual Private Cloud User
    Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        destination_cidr_block(Text, optional): The IPv4 CIDR address block used for the destination match. Routing decisions are based on the
            most specific match. We modify the specified CIDR block to its canonical form; for example, if
            you specify 100.68.0.18/18, we modify it to 100.68.0.0/18. Defaults to None.
        destination_ipv6_cidr_block(Text, optional): The IPv6 CIDR block used for the destination match. Routing decisions are based on the most
            specific match. Defaults to None.
        destination_prefix_list_id(Text, optional): The ID of a prefix list used for the destination match. Defaults to None.
        vpc_endpoint_id(Text, optional): The ID of a VPC endpoint. Supported for Gateway Load Balancer endpoints only. Defaults to None.
        egress_only_internet_gateway_id(Text, optional): [IPv6 traffic only] The ID of an egress-only internet gateway. Defaults to None.
        gateway_id(Text, optional): The ID of an internet gateway or virtual private gateway attached to your VPC. Defaults to None.
        instance_id(Text, optional): The ID of a NAT instance in your VPC. The operation fails if you specify an instance ID unless
            exactly one network interface is attached. Defaults to None.
        nat_gateway_id(Text, optional): [IPv4 traffic only] The ID of a NAT gateway. Defaults to None.
        transit_gateway_id(Text, optional): The ID of a transit gateway. Defaults to None.
        local_gateway_id(Text, optional): The ID of the local gateway. Defaults to None.
        carrier_gateway_id(Text, optional): The ID of the carrier gateway. You can only use this option when the VPC contains a subnet which
            is associated with a Wavelength Zone. Defaults to None.
        network_interface_id(Text, optional): The ID of a network interface. Defaults to None.
        route_table_id(Text): The ID of the route table for the route.
        vpc_peering_connection_id(Text, optional): The ID of a VPC peering connection. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.route.present:
                - name: value
                - route_table_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.route.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", "Route", 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_route(
                ctx,
                DryRun=ctx.test,
                
                **{"DestinationCidrBlock": destination_cidr_block, "DestinationIpv6CidrBlock": destination_ipv6_cidr_block, "DestinationPrefixListId": destination_prefix_list_id, "VpcEndpointId": vpc_endpoint_id, "EgressOnlyInternetGatewayId": egress_only_internet_gateway_id, "GatewayId": gateway_id, "InstanceId": instance_id, "NatGatewayId": nat_gateway_id, "TransitGatewayId": transit_gateway_id, "LocalGatewayId": local_gateway_id, "CarrierGatewayId": carrier_gateway_id, "NetworkInterfaceId": network_interface_id, "RouteTableId": route_table_id, "VpcPeeringConnectionId": vpc_peering_connection_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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, route_table_id: Text, destination_cidr_block: Text = None, destination_ipv6_cidr_block: Text = None, destination_prefix_list_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified route from the specified route table.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        destination_cidr_block(Text, optional): The IPv4 CIDR range for the route. The value you specify must match the CIDR for the route
            exactly. Defaults to None.
        destination_ipv6_cidr_block(Text, optional): The IPv6 CIDR range for the route. The value you specify must match the CIDR for the route
            exactly. Defaults to None.
        destination_prefix_list_id(Text, optional): The ID of the prefix list for the route. Defaults to None.
        route_table_id(Text): The ID of the route table.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.route.absent:
                - name: value
                - route_table_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.route.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", "Route", 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_route(
                ctx,
                DryRun=ctx.test,
                
                **{"DestinationCidrBlock": destination_cidr_block, "DestinationIpv6CidrBlock": destination_ipv6_cidr_block, "DestinationPrefixListId": destination_prefix_list_id, "RouteTableId": route_table_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

