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

hub.exec.boto3.client.frauddetector.delete_detector
hub.exec.boto3.client.frauddetector.describe_detector
hub.exec.boto3.client.frauddetector.get_detectors
hub.exec.boto3.client.frauddetector.put_detector
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_id: Text, event_type_name: Text, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a detector.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The detector ID.
        description(Text, optional): The description of the detector. Defaults to None.
        event_type_name(Text): The name of the event type.
        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.present:
                - name: value
                - detector_id: value
                - event_type_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.frauddetector.detector.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.describe_detector(name)

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

async def absent(hub, ctx, name: Text, detector_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the detector. Before deleting a detector, you must first delete all detector versions and rule versions
    associated with the detector. When you delete a detector, 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 detector to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

