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

hub.exec.boto3.client.iotevents.create_alarm_model
hub.exec.boto3.client.iotevents.delete_alarm_model
hub.exec.boto3.client.iotevents.describe_alarm_model
hub.exec.boto3.client.iotevents.list_alarm_models
hub.exec.boto3.client.iotevents.update_alarm_model
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, alarm_model_name: Text, role_arn: Text, alarm_rule: Dict, alarm_model_description: Text = None, tags: List = None, key: Text = None, severity: int = None, alarm_notification: Dict = None, alarm_event_actions: Dict = None, alarm_capabilities: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an alarm model to monitor an AWS IoT Events input attribute. You can use the alarm to get notified when
    the value is outside a specified range. For more information, see Create an alarm model in the AWS IoT Events
    Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        alarm_model_name(Text): A unique name that helps you identify the alarm model. You can't change this name after you
            create the alarm model.
        alarm_model_description(Text, optional): A description that tells you what the alarm model detects. Defaults to None.
        role_arn(Text): The ARN of the IAM role that allows the alarm to perform actions and access AWS resources. For
            more information, see Amazon Resource Names (ARNs) in the AWS General Reference.
        tags(List, optional): A list of key-value pairs that contain metadata for the alarm model. The tags help you manage
            the alarm model. For more information, see Tagging your AWS IoT Events resources in the AWS IoT
            Events Developer Guide. You can create up to 50 tags for one alarm model. Defaults to None.
        key(Text, optional): An input attribute used as a key to create an alarm. AWS IoT Events routes inputs associated
            with this key to the alarm. Defaults to None.
        severity(int, optional): A non-negative integer that reflects the severity level of the alarm. Defaults to None.
        alarm_rule(Dict): Defines when your alarm is invoked.
        alarm_notification(Dict, optional): Contains information about one or more notification actions. Defaults to None.
        alarm_event_actions(Dict, optional): Contains information about one or more alarm actions. Defaults to None.
        alarm_capabilities(Dict, optional): Contains the configuration information of alarm state changes. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iotevents.alarm_model.present:
                - name: value
                - alarm_model_name: value
                - role_arn: value
                - alarm_rule: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotevents.alarm_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_alarm_model(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotevents.create_alarm_model(
                ctx,
                
                
                **{"alarmModelName": alarm_model_name, "alarmModelDescription": alarm_model_description, "roleArn": role_arn, "tags": tags, "key": key, "severity": severity, "alarmRule": alarm_rule, "alarmNotification": alarm_notification, "alarmEventActions": alarm_event_actions, "alarmCapabilities": alarm_capabilities}
            )
            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_alarm_model(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, alarm_model_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an alarm model. Any alarm instances that were created based on this alarm model are also deleted. This
    action can't be undone.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        alarm_model_name(Text): The name of the alarm model.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

