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

hub.exec.boto3.client.ec2.accept_transit_gateway_peering_attachment
hub.exec.boto3.client.ec2.create_transit_gateway_peering_attachment
hub.exec.boto3.client.ec2.delete_transit_gateway_peering_attachment
hub.exec.boto3.client.ec2.describe_transit_gateway_peering_attachments
hub.exec.boto3.client.ec2.reject_transit_gateway_peering_attachment
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, transit_gateway_id: Text, peer_transit_gateway_id: Text, peer_account_id: Text, peer_region: Text, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Requests a transit gateway peering attachment between the specified transit gateway (requester) and a peer
    transit gateway (accepter). The transit gateways must be in different Regions. The peer transit gateway can be
    in your account or a different AWS account.  After you create the peering attachment, the owner of the accepter
    transit gateway must accept the attachment request.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        transit_gateway_id(Text): The ID of the transit gateway.
        peer_transit_gateway_id(Text): The ID of the peer transit gateway with which to create the peering attachment.
        peer_account_id(Text): The AWS account ID of the owner of the peer transit gateway.
        peer_region(Text): The Region where the peer transit gateway is located.
        tag_specifications(List, optional): The tags to apply to the transit gateway peering attachment. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_transit_gateway_peering_attachment(
                ctx,
                DryRun=ctx.test,
                
                **{"TransitGatewayId": transit_gateway_id, "PeerTransitGatewayId": peer_transit_gateway_id, "PeerAccountId": peer_account_id, "PeerRegion": peer_region, "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_peering_attachments(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, transit_gateway_attachment_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a transit gateway peering attachment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        transit_gateway_attachment_id(Text): The ID of the transit gateway peering attachment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

