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

hub.exec.boto3.client.globalaccelerator.create_custom_routing_endpoint_group
hub.exec.boto3.client.globalaccelerator.delete_custom_routing_endpoint_group
hub.exec.boto3.client.globalaccelerator.describe_custom_routing_endpoint_group
hub.exec.boto3.client.globalaccelerator.list_custom_routing_endpoint_groups
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, listener_arn: Text, endpoint_group_region: Text, destination_configurations: List, idempotency_token: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an endpoint group for the specified listener for a custom routing accelerator. An endpoint group is a
    collection of endpoints in one AWS Region.

    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 for a custom routing endpoint.
        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.
        destination_configurations(List): Sets the port range and protocol for all endpoints (virtual private cloud subnets) in a custom
            routing endpoint group to accept client traffic on.
        idempotency_token(Text): A unique, case-sensitive identifier that you provide to ensure the idempotency—that is, the
            uniqueness—of the request.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.globalaccelerator.create_custom_routing_endpoint_group(
                ctx,
                
                
                **{"ListenerArn": listener_arn, "EndpointGroupRegion": endpoint_group_region, "DestinationConfigurations": destination_configurations, "IdempotencyToken": idempotency_token}
            )
            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_custom_routing_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 for a custom routing accelerator.

    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.custom_routing_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.custom_routing_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_custom_routing_endpoint_group(name)

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

