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

hub.exec.boto3.client.ec2.create_traffic_mirror_session
hub.exec.boto3.client.ec2.delete_traffic_mirror_session
hub.exec.boto3.client.ec2.describe_traffic_mirror_sessions
hub.exec.boto3.client.ec2.modify_traffic_mirror_session
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, network_interface_id: Text, traffic_mirror_target_id: Text, traffic_mirror_filter_id: Text, session_number: int, packet_length: int = None, virtual_network_id: int = None, description: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Traffic Mirror session. A Traffic Mirror session actively copies packets from a Traffic Mirror source
    to a Traffic Mirror target. Create a filter, and then assign it to the session to define a subset of the traffic
    to mirror, for example all TCP traffic. The Traffic Mirror source and the Traffic Mirror target (monitoring
    appliances) can be in the same VPC, or in a different VPC connected via VPC peering or a transit gateway.  By
    default, no traffic is mirrored. Use CreateTrafficMirrorFilter to create filter rules that specify the traffic
    to mirror.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_interface_id(Text): The ID of the source network interface.
        traffic_mirror_target_id(Text): The ID of the Traffic Mirror target.
        traffic_mirror_filter_id(Text): The ID of the Traffic Mirror filter.
        packet_length(int, optional): The number of bytes in each packet to mirror. These are bytes after the VXLAN header. Do not
            specify this parameter when you want to mirror the entire packet. To mirror a subset of the
            packet, set this to the length (in bytes) that you want to mirror. For example, if you set this
            value to 100, then the first 100 bytes that meet the filter criteria are copied to the target.
            If you do not want to mirror the entire packet, use the PacketLength parameter to specify the
            number of bytes in each packet to mirror. Defaults to None.
        session_number(int): The session number determines the order in which sessions are evaluated when an interface is
            used by multiple sessions. The first session with a matching filter is the one that mirrors the
            packets. Valid values are 1-32766.
        virtual_network_id(int, optional): The VXLAN ID for the Traffic Mirror session. For more information about the VXLAN protocol, see
            RFC 7348. If you do not specify a VirtualNetworkId, an account-wide unique id is chosen at
            random. Defaults to None.
        description(Text, optional): The description of the Traffic Mirror session. Defaults to None.
        tag_specifications(List, optional): The tags to assign to a Traffic Mirror session. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.traffic_mirror_session.present:
                - name: value
                - network_interface_id: value
                - traffic_mirror_target_id: value
                - traffic_mirror_filter_id: value
                - session_number: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.traffic_mirror_session.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_traffic_mirror_sessions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_traffic_mirror_session(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"NetworkInterfaceId": network_interface_id, "TrafficMirrorTargetId": traffic_mirror_target_id, "TrafficMirrorFilterId": traffic_mirror_filter_id, "PacketLength": packet_length, "SessionNumber": session_number, "VirtualNetworkId": virtual_network_id, "Description": description, "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_traffic_mirror_sessions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, traffic_mirror_session_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Traffic Mirror session.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        traffic_mirror_session_id(Text): The ID of the Traffic Mirror session.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

