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

hub.exec.boto3.client.ec2.create_traffic_mirror_target
hub.exec.boto3.client.ec2.delete_traffic_mirror_target
hub.exec.boto3.client.ec2.describe_traffic_mirror_targets
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, network_interface_id: Text = None, network_load_balancer_arn: Text = None, description: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a target for your Traffic Mirror session. A Traffic Mirror target is the destination for mirrored
    traffic. The Traffic Mirror source and the Traffic Mirror target (monitoring appliances) can be in the same VPC,
    or in different VPCs connected via VPC peering or a transit gateway. A Traffic Mirror target can be a network
    interface, or a Network Load Balancer. To use the target in a Traffic Mirror session, use
    CreateTrafficMirrorSession.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_interface_id(Text, optional): The network interface ID that is associated with the target. Defaults to None.
        network_load_balancer_arn(Text, optional): The Amazon Resource Name (ARN) of the Network Load Balancer that is associated with the target. Defaults to None.
        description(Text, optional): The description of the Traffic Mirror target. Defaults to None.
        tag_specifications(List, optional): The tags to assign to the Traffic Mirror target. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_traffic_mirror_target(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"NetworkInterfaceId": network_interface_id, "NetworkLoadBalancerArn": network_load_balancer_arn, "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_targets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, traffic_mirror_target_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Traffic Mirror target. You cannot delete a Traffic Mirror target that is in use by a
    Traffic Mirror session.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

