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

hub.exec.boto3.client.gamelift.create_fleet
hub.exec.boto3.client.gamelift.delete_fleet
hub.exec.boto3.client.gamelift.list_fleets
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, ec2_instance_type: Text, description: Text = None, build_id: Text = None, script_id: Text = None, server_launch_path: Text = None, server_launch_parameters: Text = None, log_paths: List = None, ec2_inbound_permissions: List = None, new_game_session_protection_policy: Text = None, runtime_configuration: Dict = None, resource_creation_limit_policy: Dict = None, metric_groups: List = None, peer_vpc_aws_account_id: Text = None, peer_vpc_id: Text = None, fleet_type: Text = None, instance_role_arn: Text = None, certificate_configuration: Dict = None, locations: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a fleet of Amazon Elastic Compute Cloud (Amazon EC2) instances to host your custom game server or
    Realtime Servers. Use this operation to configure the computing resources for your fleet and provide
    instructions for running game servers on each instance. Most GameLift fleets can deploy instances to multiple
    locations, including the home Region (where the fleet is created) and an optional set of remote locations.
    Fleets that are created in the following AWS Regions support multiple locations: us-east-1 (N. Virginia), us-
    west-2 (Oregon), eu-central-1 (Frankfurt), eu-west-1 (Ireland), ap-southeast-2 (Sydney), ap-northeast-1 (Tokyo),
    and ap-northeast-2 (Seoul). Fleets that are created in other GameLift Regions can deploy instances in the
    fleet's home Region only. All fleet instances use the same configuration regardless of location; however, you
    can adjust capacity settings and turn auto-scaling on/off for each location. To create a fleet, choose the
    hardware for your instances, specify a game server build or Realtime script to deploy, and provide a runtime
    configuration to direct GameLift how to start and run game servers on each instance in the fleet. Set
    permissions for inbound traffic to your game servers, and enable optional features as needed. When creating a
    multi-location fleet, provide a list of additional remote locations. If successful, this operation creates a new
    Fleet resource and places it in NEW status, which prompts GameLift to initiate the fleet creation workflow. You
    can track fleet creation by checking fleet status using DescribeFleetAttributes and
    DescribeFleetLocationAttributes/, or by monitoring fleet creation events using DescribeFleetEvents. As soon as
    the fleet status changes to ACTIVE, you can enable automatic scaling for the fleet with PutScalingPolicy and set
    capacity for the home Region with UpdateFleetCapacity. When the status of each remote location reaches ACTIVE,
    you can set capacity by location using UpdateFleetCapacity.  Learn more   Setting up fleets   Debug fleet
    creation issues   Multi-location fleets   Related actions   CreateFleet | UpdateFleetCapacity | PutScalingPolicy
    | DescribeEC2InstanceLimits | DescribeFleetAttributes | DescribeFleetLocationAttributes | UpdateFleetAttributes
    | StopFleetActions | DeleteFleet | All APIs by task

    Args:
        name(Text): A descriptive label that is associated with a fleet. Fleet names do not need to be unique.
        description(Text, optional): A human-readable description of the fleet. Defaults to None.
        build_id(Text, optional): The unique identifier for a custom game server build to be deployed on fleet instances. You can
            use either the build ID or ARN. The build must be uploaded to GameLift and in READY status. This
            fleet property cannot be changed later. Defaults to None.
        script_id(Text, optional): The unique identifier for a Realtime configuration script to be deployed on fleet instances. You
            can use either the script ID or ARN. Scripts must be uploaded to GameLift prior to creating the
            fleet. This fleet property cannot be changed later. Defaults to None.
        server_launch_path(Text, optional):  This parameter is no longer used. Specify a server launch path using the RuntimeConfiguration
            parameter. Requests that use this parameter instead continue to be valid. Defaults to None.
        server_launch_parameters(Text, optional):  This parameter is no longer used. Specify server launch parameters using the
            RuntimeConfiguration parameter. Requests that use this parameter instead continue to be valid. Defaults to None.
        log_paths(List, optional):  This parameter is no longer used. To specify where GameLift should store log files once a
            server process shuts down, use the GameLift server API ProcessReady() and specify one or more
            directory paths in logParameters. See more information in the Server API Reference. Defaults to None.
        ec2_instance_type(Text): The GameLift-supported EC2 instance type to use for all fleet instances. Instance type
            determines the computing resources that will be used to host your game servers, including CPU,
            memory, storage, and networking capacity. See Amazon EC2 Instance Types for detailed
            descriptions of EC2 instance types.
        ec2_inbound_permissions(List, optional): The allowed IP address ranges and port settings that allow inbound traffic to access game
            sessions on this fleet. If the fleet is hosting a custom game build, this property must be set
            before players can connect to game sessions. For Realtime Servers fleets, GameLift automatically
            sets TCP and UDP ranges. Defaults to None.
        new_game_session_protection_policy(Text, optional): The status of termination protection for active game sessions on the fleet. By default, this
            property is set to NoProtection. You can also set game session protection for an individual game
            session by calling UpdateGameSession.    NoProtection - Game sessions can be terminated during
            active gameplay as a result of a scale-down event.     FullProtection - Game sessions in ACTIVE
            status cannot be terminated during a scale-down event. Defaults to None.
        runtime_configuration(Dict, optional): Instructions for how to launch and maintain server processes on instances in the fleet. The
            runtime configuration defines one or more server process configurations, each identifying a
            build executable or Realtime script file and the number of processes of that type to run
            concurrently.   The RuntimeConfiguration parameter is required unless the fleet is being
            configured using the older parameters ServerLaunchPath and ServerLaunchParameters, which are
            still supported for backward compatibility. Defaults to None.
        resource_creation_limit_policy(Dict, optional): A policy that limits the number of game sessions that an individual player can create on
            instances in this fleet within a specified span of time. Defaults to None.
        metric_groups(List, optional): The name of an AWS CloudWatch metric group to add this fleet to. A metric group is used to
            aggregate the metrics for multiple fleets. You can specify an existing metric group name or set
            a new name to create a new metric group. A fleet can be included in only one metric group at a
            time. Defaults to None.
        peer_vpc_aws_account_id(Text, optional): Used when peering your GameLift fleet with a VPC, the unique identifier for the AWS account that
            owns the VPC. You can find your account ID in the AWS Management Console under account settings. Defaults to None.
        peer_vpc_id(Text, optional): 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. Defaults to None.
        fleet_type(Text, optional): Indicates whether to use On-Demand or Spot instances for this fleet. By default, this property
            is set to ON_DEMAND. Learn more about when to use  On-Demand versus Spot Instances. This
            property cannot be changed after the fleet is created. Defaults to None.
        instance_role_arn(Text, optional): A unique identifier for an AWS IAM role that manages access to your AWS services. With an
            instance role ARN set, any application that runs on an instance in this fleet can assume the
            role, including install scripts, server processes, and daemons (background processes). Create a
            role or look up a role's ARN by using the IAM dashboard in the AWS Management Console. Learn
            more about using on-box credentials for your game servers at  Access external resources from a
            game server. This property cannot be changed after the fleet is created. Defaults to None.
        certificate_configuration(Dict, optional): Prompts GameLift to generate a TLS/SSL certificate for the fleet. TLS certificates are used for
            encrypting traffic between game clients and the game servers that are running on GameLift. By
            default, the CertificateConfiguration is set to DISABLED. Learn more at Securing Client/Server
            Communication. This property cannot be changed after the fleet is created.  Note: This feature
            requires the AWS Certificate Manager (ACM) service, which is not available in all AWS regions.
            When working in a region that does not support this feature, a fleet creation request with
            certificate generation fails with a 4xx error. Defaults to None.
        locations(List, optional): A set of remote locations to deploy additional instances to and manage as part of the fleet.
            This parameter can only be used when creating fleets in AWS Regions that support multiple
            locations. You can add any GameLift-supported AWS Region as a remote location, in the form of an
            AWS Region code such as us-west-2. To create a fleet with instances in the home Region only,
            omit this parameter. Defaults to None.
        tags(List, optional): A list of labels to assign to the new fleet resource. Tags are developer-defined key-value
            pairs. Tagging AWS resources are useful for resource management, access management and cost
            allocation. For more information, see  Tagging AWS Resources in the AWS General Reference. Once
            the fleet is created, you can use TagResource, UntagResource, and ListTagsForResource to add,
            remove, and view tags. The maximum tag limit may be lower than stated. See the AWS General
            Reference for actual tagging limits. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.create_fleet(
                ctx,
                
                
                **{"Name": name, "Description": description, "BuildId": build_id, "ScriptId": script_id, "ServerLaunchPath": server_launch_path, "ServerLaunchParameters": server_launch_parameters, "LogPaths": log_paths, "EC2InstanceType": ec2_instance_type, "EC2InboundPermissions": ec2_inbound_permissions, "NewGameSessionProtectionPolicy": new_game_session_protection_policy, "RuntimeConfiguration": runtime_configuration, "ResourceCreationLimitPolicy": resource_creation_limit_policy, "MetricGroups": metric_groups, "PeerVpcAwsAccountId": peer_vpc_aws_account_id, "PeerVpcId": peer_vpc_id, "FleetType": fleet_type, "InstanceRoleArn": instance_role_arn, "CertificateConfiguration": certificate_configuration, "Locations": locations, "Tags": tags}
            )
            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.list_fleets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, fleet_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes all resources and information related a fleet. Any current fleet instances, including those in remote
    locations, are shut down. You don't need to call DeleteFleetLocations separately.  If the fleet being deleted
    has a VPC peering connection, you first need to get a valid authorization (good for 24 hours) by calling
    CreateVpcPeeringAuthorization. You do not need to explicitly delete the VPC peering connection--this is done as
    part of the delete fleet process.  To delete a fleet, specify the fleet ID to be terminated. During the deletion
    process the fleet status is changed to DELETING. When completed, the status switches to TERMINATED and the fleet
    event FLEET_DELETED is sent.  Learn more   Setting up GameLift Fleets   Related actions   CreateFleetLocations |
    UpdateFleetAttributes | UpdateFleetCapacity | UpdateFleetPortSettings | UpdateRuntimeConfiguration |
    StopFleetActions | StartFleetActions | PutScalingPolicy | DeleteFleet | DeleteFleetLocations |
    DeleteScalingPolicy | All APIs by task

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        fleet_id(Text): A unique identifier for the fleet to be deleted. You can use either the fleet ID or ARN value.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

