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

hub.exec.boto3.client.events.delete_rule
hub.exec.boto3.client.events.describe_rule
hub.exec.boto3.client.events.disable_rule
hub.exec.boto3.client.events.enable_rule
hub.exec.boto3.client.events.list_rules
hub.exec.boto3.client.events.put_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, event_bus_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Enables the specified rule. If the rule does not exist, the operation fails. When you enable a rule, incoming
    events might not immediately start matching to a newly enabled rule. Allow a short period of time for changes to
    take effect.

    Args:
        name(Text): The name of the rule.
        event_bus_name(Text, optional): The name or ARN of the event bus associated with the rule. If you omit this, the default event
            bus is used. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.events.enable_rule(
                ctx,
                
                
                **{"Name": name, "EventBusName": event_bus_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.events.describe_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, event_bus_name: Text = None, force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified rule. Before you can delete the rule, you must remove all targets, using RemoveTargets.
    When you delete a rule, incoming events might continue to match to the deleted rule. Allow a short period of
    time for changes to take effect. If you call delete rule multiple times for the same rule, all calls will
    succeed. When you call delete rule for a non-existent custom eventbus, ResourceNotFoundException is returned.
    Managed rules are rules created and managed by another Amazon Web Services service on your behalf. These rules
    are created by those other Amazon Web Services services to support functionality in those services. You can
    delete these rules using the Force option, but you should do so only if you are sure the other service is not
    still using that rule.

    Args:
        name(Text): The name of the rule.
        event_bus_name(Text, optional): The name or ARN of the event bus associated with the rule. If you omit this, the default event
            bus is used. Defaults to None.
        force(bool, optional): If this is a managed rule, created by an Amazon Web Services service on your behalf, you must
            specify Force as True to delete the rule. This parameter is ignored for rules that are not
            managed rules. You can check whether a rule is a managed rule by using DescribeRule or ListRules
            and checking the ManagedBy field of the response. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.events.delete_rule(
                ctx,
                
                
                **{"Name": name, "EventBusName": event_bus_name, "Force": force}
            )
            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.events.describe_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

