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

hub.exec.boto3.client.ses.create_receipt_rule
hub.exec.boto3.client.ses.delete_receipt_rule
hub.exec.boto3.client.ses.describe_receipt_rule
hub.exec.boto3.client.ses.update_receipt_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rule_set_name: Text, rule: Dict, after: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a receipt rule. For information about setting up receipt rules, see the Amazon SES Developer Guide. You
    can execute this operation no more than once per second.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_set_name(Text): The name of the rule set that the receipt rule will be added to.
        after(Text, optional): The name of an existing rule after which the new rule will be placed. If this parameter is null,
            the new rule will be inserted at the beginning of the rule list. Defaults to None.
        rule(Dict): A data structure that contains the specified rule's name, actions, recipients, domains, enabled
            status, scan status, and TLS policy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ses.receipt_rule.present:
                - name: value
                - rule_set_name: value
                - rule: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ses.receipt_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.ses.describe_receipt_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ses.create_receipt_rule(
                ctx,
                
                
                **{"RuleSetName": rule_set_name, "After": after, "Rule": rule}
            )
            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.ses.describe_receipt_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rule_set_name: Text, rule_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified receipt rule. For information about managing receipt rules, see the Amazon SES Developer
    Guide. You can execute this operation no more than once per second.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_set_name(Text): The name of the receipt rule set that contains the receipt rule to delete.
        rule_name(Text): The name of the receipt rule to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

