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

hub.exec.boto3.client.iotevents.create_detector_model
hub.exec.boto3.client.iotevents.delete_detector_model
hub.exec.boto3.client.iotevents.describe_detector_model
hub.exec.boto3.client.iotevents.list_detector_models
hub.exec.boto3.client.iotevents.update_detector_model
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_model_name: Text, detector_model_definition: Dict, role_arn: Text, detector_model_description: Text = None, key: Text = None, tags: List = None, evaluation_method: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a detector model.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_model_name(Text): The name of the detector model.
        detector_model_definition(Dict): Information that defines how the detectors operate.
        detector_model_description(Text, optional): A brief description of the detector model. Defaults to None.
        key(Text, optional): The input attribute key used to identify a device or system to create a detector (an instance of
            the detector model) and then to route each input received to the appropriate detector
            (instance). This parameter uses a JSON-path expression in the message payload of each input to
            specify the attribute-value pair that is used to identify the device associated with the input. Defaults to None.
        role_arn(Text): The ARN of the role that grants permission to AWS IoT Events to perform its operations.
        tags(List, optional): Metadata that can be used to manage the detector model. Defaults to None.
        evaluation_method(Text, optional): Information about the order in which events are evaluated and how actions are executed. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iotevents.detector_model.present:
                - name: value
                - detector_model_name: value
                - detector_model_definition: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotevents.detector_model.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.iotevents.describe_detector_model(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotevents.create_detector_model(
                ctx,
                
                
                **{"detectorModelName": detector_model_name, "detectorModelDefinition": detector_model_definition, "detectorModelDescription": detector_model_description, "key": key, "roleArn": role_arn, "tags": tags, "evaluationMethod": evaluation_method}
            )
            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.iotevents.describe_detector_model(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_model_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a detector model. Any active instances of the detector model are also deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_model_name(Text): The name of the detector model to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

