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

hub.exec.boto3.client.globalaccelerator.create_endpoint_group
hub.exec.boto3.client.globalaccelerator.delete_endpoint_group
hub.exec.boto3.client.globalaccelerator.describe_endpoint_group
hub.exec.boto3.client.globalaccelerator.list_endpoint_groups
hub.exec.boto3.client.globalaccelerator.update_endpoint_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, listener_arn: Text, endpoint_group_region: Text, idempotency_token: Text, endpoint_configurations: List = None, traffic_dial_percentage: float = None, health_check_port: int = None, health_check_protocol: Text = None, health_check_path: Text = None, health_check_interval_seconds: int = None, threshold_count: int = None, port_overrides: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an endpoint group for the specified listener. An endpoint group is a collection of endpoints in one AWS
    Region. A resource must be valid and active when you add it as an endpoint.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        listener_arn(Text): The Amazon Resource Name (ARN) of the listener.
        endpoint_group_region(Text): The AWS Region where the endpoint group is located. A listener can have only one endpoint group
            in a specific Region.
        endpoint_configurations(List, optional): The list of endpoint objects. Defaults to None.
        traffic_dial_percentage(float, optional): The percentage of traffic to send to an AWS Region. Additional traffic is distributed to other
            endpoint groups for this listener.  Use this action to increase (dial up) or decrease (dial
            down) traffic to a specific Region. The percentage is applied to the traffic that would
            otherwise have been routed to the Region based on optimal routing. The default value is 100. Defaults to None.
        health_check_port(int, optional): The port that AWS Global Accelerator uses to check the health of endpoints that are part of this
            endpoint group. The default port is the listener port that this endpoint group is associated
            with. If listener port is a list of ports, Global Accelerator uses the first port in the list. Defaults to None.
        health_check_protocol(Text, optional): The protocol that AWS Global Accelerator uses to check the health of endpoints that are part of
            this endpoint group. The default value is TCP. Defaults to None.
        health_check_path(Text, optional): If the protocol is HTTP/S, then this specifies the path that is the destination for health check
            targets. The default value is slash (/). Defaults to None.
        health_check_interval_seconds(int, optional): The time—10 seconds or 30 seconds—between each health check for an endpoint. The default value
            is 30. Defaults to None.
        threshold_count(int, optional): The number of consecutive health checks required to set the state of a healthy endpoint to
            unhealthy, or to set an unhealthy endpoint to healthy. The default value is 3. Defaults to None.
        idempotency_token(Text): A unique, case-sensitive identifier that you provide to ensure the idempotency—that is, the
            uniqueness—of the request.
        port_overrides(List, optional): Override specific listener ports used to route traffic to endpoints that are part of this
            endpoint group. For example, you can create a port override in which the listener receives user
            traffic on ports 80 and 443, but your accelerator routes that traffic to ports 1080 and 1443,
            respectively, on the endpoints. For more information, see  Port overrides in the AWS Global
            Accelerator Developer Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.globalaccelerator.endpoint_group.present:
                - name: value
                - listener_arn: value
                - endpoint_group_region: value
                - idempotency_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.globalaccelerator.endpoint_group.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.globalaccelerator.describe_endpoint_group(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.globalaccelerator.create_endpoint_group(
                ctx,
                
                
                **{"ListenerArn": listener_arn, "EndpointGroupRegion": endpoint_group_region, "EndpointConfigurations": endpoint_configurations, "TrafficDialPercentage": traffic_dial_percentage, "HealthCheckPort": health_check_port, "HealthCheckProtocol": health_check_protocol, "HealthCheckPath": health_check_path, "HealthCheckIntervalSeconds": health_check_interval_seconds, "ThresholdCount": threshold_count, "IdempotencyToken": idempotency_token, "PortOverrides": port_overrides}
            )
            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.globalaccelerator.describe_endpoint_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, endpoint_group_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete an endpoint group from a listener.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_group_arn(Text): The Amazon Resource Name (ARN) of the endpoint group to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

