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

hub.exec.boto3.client.ec2.create_transit_gateway_connect_peer
hub.exec.boto3.client.ec2.delete_transit_gateway_connect_peer
hub.exec.boto3.client.ec2.describe_transit_gateway_connect_peers
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, transit_gateway_attachment_id: Text, peer_address: Text, inside_cidr_blocks: List, transit_gateway_address: Text = None, bgp_options: Dict = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Connect peer for a specified transit gateway Connect attachment between a transit gateway and an
    appliance. The peer address and transit gateway address must be the same IP address family (IPv4 or IPv6). For
    more information, see Connect peers in the Transit Gateways Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        transit_gateway_attachment_id(Text): The ID of the Connect attachment.
        transit_gateway_address(Text, optional): The peer IP address (GRE outer IP address) on the transit gateway side of the Connect peer,
            which must be specified from a transit gateway CIDR block. If not specified, Amazon
            automatically assigns the first available IP address from the transit gateway CIDR block. Defaults to None.
        peer_address(Text): The peer IP address (GRE outer IP address) on the appliance side of the Connect peer.
        bgp_options(Dict, optional): The BGP options for the Connect peer. Defaults to None.
        inside_cidr_blocks(List): The range of inside IP addresses that are used for BGP peering. You must specify a size /29 IPv4
            CIDR block from the 169.254.0.0/16 range. The first address from the range must be configured on
            the appliance as the BGP IP address. You can also optionally specify a size /125 IPv6 CIDR block
            from the fd00::/8 range.
        tag_specifications(List, optional): The tags to apply to the Connect peer. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_transit_gateway_connect_peer(
                ctx,
                DryRun=ctx.test,
                
                **{"TransitGatewayAttachmentId": transit_gateway_attachment_id, "TransitGatewayAddress": transit_gateway_address, "PeerAddress": peer_address, "BgpOptions": bgp_options, "InsideCidrBlocks": inside_cidr_blocks, "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_transit_gateway_connect_peers(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, transit_gateway_connect_peer_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Connect peer.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        transit_gateway_connect_peer_id(Text): The ID of the Connect peer.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

