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

hub.exec.boto3.client.ec2.accept_transit_gateway_vpc_attachment
hub.exec.boto3.client.ec2.create_transit_gateway_vpc_attachment
hub.exec.boto3.client.ec2.delete_transit_gateway_vpc_attachment
hub.exec.boto3.client.ec2.describe_transit_gateway_vpc_attachments
hub.exec.boto3.client.ec2.modify_transit_gateway_vpc_attachment
hub.exec.boto3.client.ec2.reject_transit_gateway_vpc_attachment
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, transit_gateway_id: Text, vpc_id: Text, subnet_ids: List, options: Dict = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Attaches the specified VPC to the specified transit gateway. If you attach a VPC with a CIDR range that overlaps
    the CIDR range of a VPC that is already attached, the new VPC CIDR range is not propagated to the default
    propagation route table. To send VPC traffic to an attached transit gateway, add a route to the VPC route table
    using CreateRoute.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        transit_gateway_id(Text): The ID of the transit gateway.
        vpc_id(Text): The ID of the VPC.
        subnet_ids(List): The IDs of one or more subnets. You can specify only one subnet per Availability Zone. You must
            specify at least one subnet, but we recommend that you specify two subnets for better
            availability. The transit gateway uses one IP address from each specified subnet.
        options(Dict, optional): The VPC attachment options. Defaults to None.
        tag_specifications(List, optional): The tags to apply to the VPC attachment. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_transit_gateway_vpc_attachment(
                ctx,
                DryRun=ctx.test,
                
                **{"TransitGatewayId": transit_gateway_id, "VpcId": vpc_id, "SubnetIds": subnet_ids, "Options": options, "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_vpc_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 the specified VPC attachment.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.transit_gateway_vpc_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_vpc_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_vpc_attachments(name)

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

