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

hub.exec.boto3.client.frauddetector.create_detector_version
hub.exec.boto3.client.frauddetector.delete_detector_version
hub.exec.boto3.client.frauddetector.get_detector_version
hub.exec.boto3.client.frauddetector.update_detector_version
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_id: Text, rules: List, description: Text = None, external_model_endpoints: List = None, model_versions: List = None, rule_execution_mode: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a detector version. The detector version starts in a DRAFT status.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The ID of the detector under which you want to create a new version.
        description(Text, optional): The description of the detector version. Defaults to None.
        external_model_endpoints(List, optional): The Amazon Sagemaker model endpoints to include in the detector version. Defaults to None.
        rules(List): The rules to include in the detector version.
        model_versions(List, optional): The model versions to include in the detector version. Defaults to None.
        rule_execution_mode(Text, optional): The rule execution mode for the rules included in the detector version. You can define and edit
            the rule mode at the detector version level, when it is in draft status. If you specify
            FIRST_MATCHED, Amazon Fraud Detector evaluates rules sequentially, first to last, stopping at
            the first matched rule. Amazon Fraud dectector then provides the outcomes for that single rule.
            If you specifiy ALL_MATCHED, Amazon Fraud Detector evaluates all rules and returns the outcomes
            for all matched rules.  The default behavior is FIRST_MATCHED. Defaults to None.
        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.detector_version.present:
                - name: value
                - detector_id: value
                - rules: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.frauddetector.detector_version.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_detector_version(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.frauddetector.create_detector_version(
                ctx,
                
                
                **{"detectorId": detector_id, "description": description, "externalModelEndpoints": external_model_endpoints, "rules": rules, "modelVersions": model_versions, "ruleExecutionMode": rule_execution_mode, "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_detector_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text, detector_version_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the detector version. You cannot delete detector versions that are in ACTIVE status. When you delete a
    detector version, Amazon Fraud Detector permanently deletes the detector 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.
        detector_id(Text): The ID of the parent detector for the detector version to delete.
        detector_version_id(Text): The ID of the detector version to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

