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

hub.exec.boto3.client.route53_recovery_control_config.create_safety_rule
hub.exec.boto3.client.route53_recovery_control_config.delete_safety_rule
hub.exec.boto3.client.route53_recovery_control_config.describe_safety_rule
hub.exec.boto3.client.route53_recovery_control_config.list_safety_rules
hub.exec.boto3.client.route53_recovery_control_config.update_safety_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, assertion_rule: Dict = None, gating_rule: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a safety rule in a control panel. Safety rules let you add safeguards around enabling and disabling
    routing controls, to help prevent unexpected outcomes. There are two types of safety rules: assertion rules and
    gating rules. Assertion rule: An assertion rule enforces that, when a routing control state is changed, the
    criteria set by the rule configuration is met. Otherwise, the change to the routing control is not accepted.
    Gating rule: A gating rule verifies that a set of gating controls evaluates as true, based on a rule
    configuration that you specify. If the gating rule evaluates to true, Amazon Route 53 Application Recovery
    Controller allows a set of routing control state changes to run and complete against the set of target controls.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        assertion_rule(Dict, optional): A new assertion rule for a control panel. Defaults to None.
        gating_rule(Dict, optional): A new gating rule for a control panel. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.route53_recovery_control_config.create_safety_rule(
                ctx,
                
                ClientToken=name,
                **{"AssertionRule": assertion_rule, "GatingRule": gating_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.route53_recovery_control_config.describe_safety_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        safety_rule_arn(Text): The request body that you include when you update a safety rule.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

