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

hub.exec.boto3.client.iot.create_topic_rule
hub.exec.boto3.client.iot.delete_topic_rule
hub.exec.boto3.client.iot.disable_topic_rule
hub.exec.boto3.client.iot.enable_topic_rule
hub.exec.boto3.client.iot.get_topic_rule
hub.exec.boto3.client.iot.list_topic_rules
hub.exec.boto3.client.iot.replace_topic_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rule_name: Text, topic_rule_payload: Dict, tags: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a rule. Creating rules is an administrator-level action. Any user who has permission to create rules
    will be able to access data processed by the rule.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_name(Text): The name of the rule.
        topic_rule_payload(Dict): The rule payload.
        tags(Text, optional): Metadata which can be used to manage the topic rule.  For URI Request parameters use format:
            ...key1=value1&key2=value2... For the CLI command-line parameter use format: --tags
            "key1=value1&key2=value2..." For the cli-input-json file use format: "tags":
            "key1=value1&key2=value2...". Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.topic_rule.present:
                - name: value
                - rule_name: value
                - topic_rule_payload: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.topic_rule.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.iot.get_topic_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_topic_rule(
                ctx,
                
                
                **{"ruleName": rule_name, "topicRulePayload": topic_rule_payload, "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.iot.get_topic_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_name(Text): The name of the rule.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

