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

hub.exec.boto3.client.ds.deregister_event_topic
hub.exec.boto3.client.ds.describe_event_topics
hub.exec.boto3.client.ds.register_event_topic
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_id: Text, topic_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a directory with an Amazon SNS topic. This establishes the directory as a publisher to the specified
    Amazon SNS topic. You can then receive email or text (SMS) messages when the status of your directory changes.
    You get notified if your directory goes from an Active status to an Impaired or Inoperable status. You also
    receive a notification when the directory returns to an Active status.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The Directory ID that will publish status messages to the Amazon SNS topic.
        topic_name(Text): The Amazon SNS topic name to which the directory will publish status messages. This Amazon SNS
            topic must be in the same region as the specified Directory ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ds.event_topic.present:
                - name: value
                - directory_id: value
                - topic_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ds.event_topic.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.ds.describe_event_topics(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.register_event_topic(
                ctx,
                
                
                **{"DirectoryId": directory_id, "TopicName": topic_name}
            )
            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.ds.describe_event_topics(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_id: Text, topic_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the specified directory as a publisher to the specified Amazon SNS topic.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The Directory ID to remove as a publisher. This directory will no longer send messages to the
            specified Amazon SNS topic.
        topic_name(Text): The name of the Amazon SNS topic from which to remove the directory as a publisher.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

