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

hub.exec.boto3.client.redshift.create_event_subscription
hub.exec.boto3.client.redshift.delete_event_subscription
hub.exec.boto3.client.redshift.describe_event_subscriptions
hub.exec.boto3.client.redshift.modify_event_subscription
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subscription_name: Text, sns_topic_arn: Text, source_type: Text = None, source_ids: List = None, event_categories: List = None, severity: Text = None, enabled: bool = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Redshift event notification subscription. This action requires an ARN (Amazon Resource Name)
    of an Amazon SNS topic created by either the Amazon Redshift console, the Amazon SNS console, or the Amazon SNS
    API. To obtain an ARN with Amazon SNS, you must create a topic in Amazon SNS and subscribe to the topic. The ARN
    is displayed in the SNS console. You can specify the source type, and lists of Amazon Redshift source IDs, event
    categories, and event severities. Notifications will be sent for all events you want that match those criteria.
    For example, you can specify source type = cluster, source ID = my-cluster-1 and mycluster2, event categories =
    Availability, Backup, and severity = ERROR. The subscription will only send notifications for those ERROR events
    in the Availability and Backup categories for the specified clusters. If you specify both the source type and
    source IDs, such as source type = cluster and source identifier = my-cluster-1, notifications will be sent for
    all the cluster events for my-cluster-1. If you specify a source type but do not specify a source identifier,
    you will receive notice of the events for the objects of that type in your Amazon Web Services account. If you
    do not specify either the SourceType nor the SourceIdentifier, you will be notified of events generated from all
    Amazon Redshift sources belonging to your Amazon Web Services account. You must specify a source type if you
    specify a source ID.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        subscription_name(Text): The name of the event subscription to be created. Constraints:   Cannot be null, empty, or
            blank.   Must contain from 1 to 255 alphanumeric characters or hyphens.   First character must
            be a letter.   Cannot end with a hyphen or contain two consecutive hyphens.
        sns_topic_arn(Text): The Amazon Resource Name (ARN) of the Amazon SNS topic used to transmit the event notifications.
            The ARN is created by Amazon SNS when you create a topic and subscribe to it.
        source_type(Text, optional): The type of source that will be generating the events. For example, if you want to be notified
            of events generated by a cluster, you would set this parameter to cluster. If this value is not
            specified, events are returned for all Amazon Redshift objects in your Amazon Web Services
            account. You must specify a source type in order to specify source IDs. Valid values: cluster,
            cluster-parameter-group, cluster-security-group, cluster-snapshot, and scheduled-action. Defaults to None.
        source_ids(List, optional): A list of one or more identifiers of Amazon Redshift source objects. All of the objects must be
            of the same type as was specified in the source type parameter. The event subscription will
            return only events generated by the specified objects. If not specified, then events are
            returned for all objects within the source type specified. Example: my-cluster-1, my-cluster-2
            Example: my-snapshot-20131010. Defaults to None.
        event_categories(List, optional): Specifies the Amazon Redshift event categories to be published by the event notification
            subscription. Values: configuration, management, monitoring, security, pending. Defaults to None.
        severity(Text, optional): Specifies the Amazon Redshift event severity to be published by the event notification
            subscription. Values: ERROR, INFO. Defaults to None.
        enabled(bool, optional): A boolean value; set to true to activate the subscription, and set to false to create the
            subscription but not activate it. Defaults to None.
        tags(List, optional): A list of tag instances. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.event_subscription.present:
                - name: value
                - subscription_name: value
                - sns_topic_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.event_subscription.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.redshift.describe_event_subscriptions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_event_subscription(
                ctx,
                
                
                **{"SubscriptionName": subscription_name, "SnsTopicArn": sns_topic_arn, "SourceType": source_type, "SourceIds": source_ids, "EventCategories": event_categories, "Severity": severity, "Enabled": enabled, "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.redshift.describe_event_subscriptions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, subscription_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon Redshift event notification subscription.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        subscription_name(Text): The name of the Amazon Redshift event notification subscription to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

