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

hub.exec.boto3.client.frauddetector.create_rule
hub.exec.boto3.client.frauddetector.delete_rule
hub.exec.boto3.client.frauddetector.get_rules
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rule_id: Text, detector_id: Text, expression: Text, language: Text, outcomes: List, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a rule for use with the specified detector.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rule_id(Text): The rule ID.
        detector_id(Text): The detector ID for the rule's parent detector.
        description(Text, optional): The rule description. Defaults to None.
        expression(Text): The rule expression.
        language(Text): The language of the rule.
        outcomes(List): The outcome or outcomes returned when the rule expression matches.
        tags(List, optional): A collection of key and value pairs. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.frauddetector.rule.present:
                - name: value
                - rule_id: value
                - detector_id: value
                - expression: value
                - language: value
                - outcomes: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.frauddetector.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.frauddetector.get_rules(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.frauddetector.create_rule(
                ctx,
                
                
                **{"ruleId": rule_id, "detectorId": detector_id, "description": description, "expression": expression, "language": language, "outcomes": outcomes, "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.frauddetector.get_rules(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rule: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the rule. You cannot delete a rule if it is used by an ACTIVE or INACTIVE detector version. When you
    delete a rule, Amazon Fraud Detector permanently deletes that rule and the data is no longer stored in Amazon
    Fraud Detector.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

