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

hub.exec.boto3.client.globalaccelerator.create_custom_routing_accelerator
hub.exec.boto3.client.globalaccelerator.delete_custom_routing_accelerator
hub.exec.boto3.client.globalaccelerator.describe_custom_routing_accelerator
hub.exec.boto3.client.globalaccelerator.list_custom_routing_accelerators
hub.exec.boto3.client.globalaccelerator.update_custom_routing_accelerator
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, idempotency_token: Text, ip_address_type: Text = None, ip_addresses: List = None, enabled: bool = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a custom routing accelerator. A custom routing accelerator directs traffic to one of possibly thousands
    of Amazon EC2 instance destinations running in a single or multiple virtual private clouds (VPC) subnet
    endpoints. Be aware that, by default, all destination EC2 instances in a VPC subnet endpoint cannot receive
    traffic. To enable all destinations to receive traffic, or to specify individual port mappings that can receive
    traffic, see the  AllowCustomRoutingTraffic operation.  Global Accelerator is a global service that supports
    endpoints in multiple AWS Regions but you must specify the US West (Oregon) Region to create or update
    accelerators.

    Args:
        name(Text): The name of a custom routing accelerator. The name can have a maximum of 64 characters, must
            contain only alphanumeric characters or hyphens (-), and must not begin or end with a hyphen.
        ip_address_type(Text, optional): The value for the address type must be IPv4. Defaults to None.
        ip_addresses(List, optional): Optionally, if you've added your own IP address pool to Global Accelerator (BYOIP), you can
            choose IP addresses from your own pool to use for the accelerator's static IP addresses when you
            create an accelerator. You can specify one or two addresses, separated by a space. Do not
            include the /32 suffix. Only one IP address from each of your IP address ranges can be used for
            each accelerator. If you specify only one IP address from your IP address range, Global
            Accelerator assigns a second static IP address for the accelerator from the AWS IP address pool.
            Note that you can't update IP addresses for an existing accelerator. To change them, you must
            create a new accelerator with the new addresses. For more information, see Bring your own IP
            addresses (BYOIP) in the AWS Global Accelerator Developer Guide. Defaults to None.
        enabled(bool, optional): Indicates whether an accelerator is enabled. The value is true or false. The default value is
            true.  If the value is set to true, an accelerator cannot be deleted. If set to false, the
            accelerator can be deleted. 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.
        tags(List, optional): Create tags for an accelerator. For more information, see Tagging in AWS Global Accelerator in
            the AWS Global Accelerator Developer Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.globalaccelerator.create_custom_routing_accelerator(
                ctx,
                
                
                **{"Name": name, "IpAddressType": ip_address_type, "IpAddresses": ip_addresses, "Enabled": enabled, "IdempotencyToken": idempotency_token, "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.globalaccelerator.describe_custom_routing_accelerator(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, accelerator_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a custom routing accelerator. Before you can delete an accelerator, you must disable it and remove all
    dependent resources (listeners and endpoint groups). To disable the accelerator, update the accelerator to set
    Enabled to false.  When you create a custom routing accelerator, by default, Global Accelerator provides you
    with a set of two static IP addresses.  The IP addresses are assigned to your accelerator for as long as it
    exists, even if you disable the accelerator and it no longer accepts or routes traffic. However, when you delete
    an accelerator, you lose the static IP addresses that are assigned to the accelerator, so you can no longer
    route traffic by using them. As a best practice, ensure that you have permissions in place to avoid
    inadvertently deleting accelerators. You can use IAM policies with Global Accelerator to limit the users who
    have permissions to delete an accelerator. For more information, see Authentication and Access Control in the
    AWS Global Accelerator Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        accelerator_arn(Text): The Amazon Resource Name (ARN) of the custom routing accelerator to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

