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

hub.exec.boto3.client.lambda_.delete_function_event_invoke_config
hub.exec.boto3.client.lambda_.get_function_event_invoke_config
hub.exec.boto3.client.lambda_.list_function_event_invoke_configs
hub.exec.boto3.client.lambda_.put_function_event_invoke_config
hub.exec.boto3.client.lambda_.update_function_event_invoke_config
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, function_name: Text, qualifier: Text = None, maximum_retry_attempts: int = None, maximum_event_age_in_seconds: int = None, destination_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Configures options for asynchronous invocation on a function, version, or alias. If a configuration already
    exists for a function, version, or alias, this operation overwrites it. If you exclude any settings, they are
    removed. To set one option without affecting existing settings for other options, use
    UpdateFunctionEventInvokeConfig. By default, Lambda retries an asynchronous invocation twice if the function
    returns an error. It retains events in a queue for up to six hours. When an event fails all processing attempts
    or stays in the asynchronous invocation queue for too long, Lambda discards it. To retain discarded events,
    configure a dead-letter queue with UpdateFunctionConfiguration. To send an invocation record to a queue, topic,
    function, or event bus, specify a destination. You can configure separate destinations for successful
    invocations (on-success) and events that fail all processing attempts (on-failure). You can configure
    destinations in addition to or instead of a dead-letter queue.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        function_name(Text): The name of the Lambda function, version, or alias.  Name formats     Function name - my-
            function (name-only), my-function:v1 (with alias).    Function ARN - arn:aws:lambda:us-
            west-2:123456789012:function:my-function.    Partial ARN - 123456789012:function:my-function.
            You can append a version number or alias to any of the formats. The length constraint applies
            only to the full ARN. If you specify only the function name, it is limited to 64 characters in
            length.
        qualifier(Text, optional): A version number or alias name. Defaults to None.
        maximum_retry_attempts(int, optional): The maximum number of times to retry when the function returns an error. Defaults to None.
        maximum_event_age_in_seconds(int, optional): The maximum age of a request that Lambda sends to a function for processing. Defaults to None.
        destination_config(Dict, optional): A destination for events after they have been sent to a function for processing.  Destinations
            Function - The Amazon Resource Name (ARN) of a Lambda function.    Queue - The ARN of an SQS
            queue.    Topic - The ARN of an SNS topic.    Event Bus - The ARN of an Amazon EventBridge event
            bus. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lambda_.put_function_event_invoke_config(
                ctx,
                
                
                **{"FunctionName": function_name, "Qualifier": qualifier, "MaximumRetryAttempts": maximum_retry_attempts, "MaximumEventAgeInSeconds": maximum_event_age_in_seconds, "DestinationConfig": destination_config}
            )
            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.lambda_.get_function_event_invoke_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, function_name: Text, qualifier: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the configuration for asynchronous invocation for a function, version, or alias. To configure options
    for asynchronous invocation, use PutFunctionEventInvokeConfig.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        function_name(Text): The name of the Lambda function, version, or alias.  Name formats     Function name - my-
            function (name-only), my-function:v1 (with alias).    Function ARN - arn:aws:lambda:us-
            west-2:123456789012:function:my-function.    Partial ARN - 123456789012:function:my-function.
            You can append a version number or alias to any of the formats. The length constraint applies
            only to the full ARN. If you specify only the function name, it is limited to 64 characters in
            length.
        qualifier(Text, optional): A version number or alias name. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

