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

hub.exec.boto3.client.gamelift.create_vpc_peering_authorization
hub.exec.boto3.client.gamelift.delete_vpc_peering_authorization
hub.exec.boto3.client.gamelift.describe_vpc_peering_authorizations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, game_lift_aws_account_id: Text, peer_vpc_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Requests authorization to create or delete a peer connection between the VPC for your Amazon GameLift fleet and
    a virtual private cloud (VPC) in your AWS account. VPC peering enables the game servers on your fleet to
    communicate directly with other AWS resources. Once you've received authorization, call
    CreateVpcPeeringConnection to establish the peering connection. For more information, see VPC Peering with
    Amazon GameLift Fleets. You can peer with VPCs that are owned by any AWS account you have access to, including
    the account that you use to manage your Amazon GameLift fleets. You cannot peer with VPCs that are in different
    Regions. To request authorization to create a connection, call this operation from the AWS account with the VPC
    that you want to peer to your Amazon GameLift fleet. For example, to enable your game servers to retrieve data
    from a DynamoDB table, use the account that manages that DynamoDB resource. Identify the following values: (1)
    The ID of the VPC that you want to peer with, and (2) the ID of the AWS account that you use to manage Amazon
    GameLift. If successful, VPC peering is authorized for the specified VPC.  To request authorization to delete a
    connection, call this operation from the AWS account with the VPC that is peered with your Amazon GameLift
    fleet. Identify the following values: (1) VPC ID that you want to delete the peering connection for, and (2) ID
    of the AWS account that you use to manage Amazon GameLift.  The authorization remains valid for 24 hours unless
    it is canceled by a call to DeleteVpcPeeringAuthorization. You must create or delete the peering connection
    while the authorization is valid.   Related actions   CreateVpcPeeringAuthorization |
    DescribeVpcPeeringAuthorizations | DeleteVpcPeeringAuthorization | CreateVpcPeeringConnection |
    DescribeVpcPeeringConnections | DeleteVpcPeeringConnection | All APIs by task

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        game_lift_aws_account_id(Text): A unique identifier for the AWS account that you use to manage your GameLift fleet. You can find
            your Account ID in the AWS Management Console under account settings.
        peer_vpc_id(Text): A unique identifier for a VPC with resources to be accessed by your GameLift fleet. The VPC must
            be in the same Region as your fleet. To look up a VPC ID, use the VPC Dashboard in the AWS
            Management Console. Learn more about VPC peering in VPC Peering with GameLift Fleets.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.create_vpc_peering_authorization(
                ctx,
                
                
                **{"GameLiftAwsAccountId": game_lift_aws_account_id, "PeerVpcId": peer_vpc_id}
            )
            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.gamelift.describe_vpc_peering_authorizations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, game_lift_aws_account_id: Text, peer_vpc_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Cancels a pending VPC peering authorization for the specified VPC. If you need to delete an existing VPC peering
    connection, call DeleteVpcPeeringConnection.   Related actions   CreateVpcPeeringAuthorization |
    DescribeVpcPeeringAuthorizations | DeleteVpcPeeringAuthorization | CreateVpcPeeringConnection |
    DescribeVpcPeeringConnections | DeleteVpcPeeringConnection | All APIs by task

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        game_lift_aws_account_id(Text): A unique identifier for the AWS account that you use to manage your GameLift fleet. You can find
            your Account ID in the AWS Management Console under account settings.
        peer_vpc_id(Text): A unique identifier for a VPC with resources to be accessed by your GameLift fleet. The VPC must
            be in the same Region as your fleet. To look up a VPC ID, use the VPC Dashboard in the AWS
            Management Console. Learn more about VPC peering in VPC Peering with GameLift Fleets.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.gamelift.vpc_peering_authorization.absent:
                - name: value
                - game_lift_aws_account_id: value
                - peer_vpc_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.gamelift.vpc_peering_authorization.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.gamelift.describe_vpc_peering_authorizations(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.delete_vpc_peering_authorization(
                ctx,
                
                
                **{"GameLiftAwsAccountId": game_lift_aws_account_id, "PeerVpcId": peer_vpc_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.gamelift.describe_vpc_peering_authorizations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

