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

hub.exec.boto3.client.ec2.accept_vpc_peering_connection
hub.exec.boto3.client.ec2.create_vpc_peering_connection
hub.exec.boto3.client.ec2.delete_vpc_peering_connection
hub.exec.boto3.client.ec2.describe_vpc_peering_connections
hub.exec.boto3.client.ec2.reject_vpc_peering_connection
resource = hub.tool.boto3.resource.create(ctx, "ec2", "VpcPeeringConnection", name)
hub.tool.boto3.resource.exec(resource, accept, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, reject, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, peer_owner_id: Text = None, peer_vpc_id: Text = None, vpc_id: Text = None, peer_region: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Requests a VPC peering connection between two VPCs: a requester VPC that you own and an accepter VPC with which
    to create the connection. The accepter VPC can belong to another Amazon Web Services account and can be in a
    different Region to the requester VPC. The requester VPC and accepter VPC cannot have overlapping CIDR blocks.
    Limitations and rules apply to a VPC peering connection. For more information, see the limitations section in
    the VPC Peering Guide.  The owner of the accepter VPC must accept the peering request to activate the peering
    connection. The VPC peering connection request expires after 7 days, after which it cannot be accepted or
    rejected. If you create a VPC peering connection request between VPCs with overlapping CIDR blocks, the VPC
    peering connection has a status of failed.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        peer_owner_id(Text, optional): The Amazon Web Services account ID of the owner of the accepter VPC. Default: Your Amazon Web
            Services account ID. Defaults to None.
        peer_vpc_id(Text, optional): The ID of the VPC with which you are creating the VPC peering connection. You must specify this
            parameter in the request. Defaults to None.
        vpc_id(Text, optional): The ID of the requester VPC. You must specify this parameter in the request. Defaults to None.
        peer_region(Text, optional): The Region code for the accepter VPC, if the accepter VPC is located in a Region other than the
            Region in which you make the request. Default: The Region in which you make the request. Defaults to None.
        tag_specifications(List, optional): The tags to assign to the peering connection. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.vpc_peering_connection.present:
                - name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.vpc_peering_connection.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "VpcPeeringConnection", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_vpc_peering_connection(
                ctx,
                DryRun=ctx.test,
                
                **{"PeerOwnerId": peer_owner_id, "PeerVpcId": peer_vpc_id, "VpcId": vpc_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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, vpc_peering_connection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a VPC peering connection. Either the owner of the requester VPC or the owner of the accepter VPC can
    delete the VPC peering connection if it's in the active state. The owner of the requester VPC can delete a VPC
    peering connection in the pending-acceptance state. You cannot delete a VPC peering connection that's in the
    failed state.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        vpc_peering_connection_id(Text): The ID of the VPC peering connection.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.vpc_peering_connection.absent:
                - name: value
                - vpc_peering_connection_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.vpc_peering_connection.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "ec2", "VpcPeeringConnection", name)

    before = await hub.tool.boto3.resource.describe(resource)

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

