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

hub.exec.boto3.client.events.create_api_destination
hub.exec.boto3.client.events.delete_api_destination
hub.exec.boto3.client.events.describe_api_destination
hub.exec.boto3.client.events.list_api_destinations
hub.exec.boto3.client.events.update_api_destination
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, connection_arn: Text, invocation_endpoint: Text, http_method: Text, description: Text = None, invocation_rate_limit_per_second: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an API destination, which is an HTTP invocation endpoint configured as a target for events.

    Args:
        name(Text): The name for the API destination to create.
        description(Text, optional): A description for the API destination to create. Defaults to None.
        connection_arn(Text): The ARN of the connection to use for the API destination. The destination endpoint must support
            the authorization type specified for the connection.
        invocation_endpoint(Text): The URL to the HTTP invocation endpoint for the API destination.
        http_method(Text): The method to use for the request to the HTTP invocation endpoint.
        invocation_rate_limit_per_second(int, optional): The maximum number of requests per second to send to the HTTP invocation endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.events.api_destination.present:
                - name: value
                - connection_arn: value
                - invocation_endpoint: value
                - http_method: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.events.api_destination.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.events.describe_api_destination(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.events.create_api_destination(
                ctx,
                
                
                **{"Name": name, "Description": description, "ConnectionArn": connection_arn, "InvocationEndpoint": invocation_endpoint, "HttpMethod": http_method, "InvocationRateLimitPerSecond": invocation_rate_limit_per_second}
            )
            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.events.describe_api_destination(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified API destination.

    Args:
        name(Text): The name of the destination to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

