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

hub.exec.boto3.client.gamelift.claim_game_server
hub.exec.boto3.client.gamelift.deregister_game_server
hub.exec.boto3.client.gamelift.describe_game_server
hub.exec.boto3.client.gamelift.list_game_servers
hub.exec.boto3.client.gamelift.register_game_server
hub.exec.boto3.client.gamelift.update_game_server
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, game_server_group_name: Text, game_server_id: Text, instance_id: Text, connection_info: Text = None, game_server_data: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This operation is used with the GameLift FleetIQ solution and game server groups.  Creates a new game server
    resource and notifies GameLift FleetIQ that the game server is ready to host gameplay and players. This
    operation is called by a game server process that is running on an instance in a game server group. Registering
    game servers enables GameLift FleetIQ to track available game servers and enables game clients and services to
    claim a game server for a new game session.  To register a game server, identify the game server group and
    instance where the game server is running, and provide a unique identifier for the game server. You can also
    include connection and game server data. When a game client or service requests a game server by calling
    ClaimGameServer, this information is returned in the response. Once a game server is successfully registered, it
    is put in status AVAILABLE. A request to register a game server may fail if the instance it is running on is in
    the process of shutting down as part of instance balancing or scale-down activity.   Learn more   GameLift
    FleetIQ Guide   Related actions   RegisterGameServer | ListGameServers | ClaimGameServer | DescribeGameServer |
    UpdateGameServer | DeregisterGameServer | All APIs by task

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        game_server_group_name(Text): A unique identifier for the game server group where the game server is running. Use either the
            GameServerGroup name or ARN value.
        game_server_id(Text): A custom string that uniquely identifies the game server to register. Game server IDs are
            developer-defined and must be unique across all game server groups in your AWS account.
        instance_id(Text): The unique identifier for the instance where the game server is running. This ID is available in
            the instance metadata. EC2 instance IDs use a 17-character format, for example:
            i-1234567890abcdef0.
        connection_info(Text, optional): Information that is needed to make inbound client connections to the game server. This might
            include the IP address and port, DNS name, and other information. Defaults to None.
        game_server_data(Text, optional): A set of custom game server properties, formatted as a single string value. This data is passed
            to a game client or service when it requests information on game servers using ListGameServers
            or ClaimGameServer. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.gamelift.game_server.present:
                - name: value
                - game_server_group_name: value
                - game_server_id: value
                - instance_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.gamelift.game_server.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_game_server(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.register_game_server(
                ctx,
                
                
                **{"GameServerGroupName": game_server_group_name, "GameServerId": game_server_id, "InstanceId": instance_id, "ConnectionInfo": connection_info, "GameServerData": game_server_data}
            )
            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_game_server(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, game_server_group_name: Text, game_server_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     This operation is used with the GameLift FleetIQ solution and game server groups.  Removes the game server from
    a game server group. As a result of this operation, the deregistered game server can no longer be claimed and
    will not be returned in a list of active game servers.  To deregister a game server, specify the game server
    group and game server ID. If successful, this operation emits a CloudWatch event with termination timestamp and
    reason.  Learn more   GameLift FleetIQ Guide   Related actions   RegisterGameServer | ListGameServers |
    ClaimGameServer | DescribeGameServer | UpdateGameServer | DeregisterGameServer | All APIs by task

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        game_server_group_name(Text): A unique identifier for the game server group where the game server is running. Use either the
            GameServerGroup name or ARN value.
        game_server_id(Text): A custom string that uniquely identifies the game server to deregister.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.deregister_game_server(
                ctx,
                
                
                **{"GameServerGroupName": game_server_group_name, "GameServerId": game_server_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_game_server(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

