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

hub.exec.boto3.client.lookoutmetrics.create_alert
hub.exec.boto3.client.lookoutmetrics.delete_alert
hub.exec.boto3.client.lookoutmetrics.describe_alert
hub.exec.boto3.client.lookoutmetrics.list_alerts
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, alert_name: Text, alert_sensitivity_threshold: int, anomaly_detector_arn: Text, action: Dict, alert_description: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an alert for an anomaly detector.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        alert_name(Text): The name of the alert.
        alert_sensitivity_threshold(int): An integer from 0 to 100 specifying the alert sensitivity threshold.
        alert_description(Text, optional): A description of the alert. Defaults to None.
        anomaly_detector_arn(Text): The ARN of the detector to which the alert is attached.
        action(Dict): Action that will be triggered when there is an alert.
        tags(Dict, optional): A list of tags to apply to the alert. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lookoutmetrics.alert.present:
                - name: value
                - alert_name: value
                - alert_sensitivity_threshold: value
                - anomaly_detector_arn: value
                - action: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lookoutmetrics.alert.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.lookoutmetrics.describe_alert(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lookoutmetrics.create_alert(
                ctx,
                
                
                **{"AlertName": alert_name, "AlertSensitivityThreshold": alert_sensitivity_threshold, "AlertDescription": alert_description, "AnomalyDetectorArn": anomaly_detector_arn, "Action": action, "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.lookoutmetrics.describe_alert(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, alert_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an alert.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        alert_arn(Text): The ARN of the alert to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

