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

hub.exec.boto3.client.autoscaling.delete_notification_configuration
hub.exec.boto3.client.autoscaling.describe_notification_configurations
hub.exec.boto3.client.autoscaling.put_notification_configuration
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, auto_scaling_group_name: Text, topic_arn: Text, notification_types: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Configures an Auto Scaling group to send notifications when specified events take place. Subscribers to the
    specified topic can have messages delivered to an endpoint such as a web server or an email address. This
    configuration overwrites any existing configuration. For more information, see Getting Amazon SNS notifications
    when your Auto Scaling group scales in the Amazon EC2 Auto Scaling User Guide. If you exceed your maximum limit
    of SNS topics, which is 10 per Auto Scaling group, the call fails.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        auto_scaling_group_name(Text): The name of the Auto Scaling group.
        topic_arn(Text): The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (Amazon SNS) topic.
        notification_types(List): The type of event that causes the notification to be sent. To query the notification types
            supported by Amazon EC2 Auto Scaling, call the DescribeAutoScalingNotificationTypes API.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.autoscaling.notification_configuration.present:
                - name: value
                - auto_scaling_group_name: value
                - topic_arn: value
                - notification_types: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.autoscaling.notification_configuration.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.autoscaling.describe_notification_configurations(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.autoscaling.put_notification_configuration(
                ctx,
                
                
                **{"AutoScalingGroupName": auto_scaling_group_name, "TopicARN": topic_arn, "NotificationTypes": notification_types}
            )
            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.autoscaling.describe_notification_configurations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        auto_scaling_group_name(Text): The name of the Auto Scaling group.
        topic_arn(Text): The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (Amazon SNS) topic.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

