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

hub.exec.boto3.client.cloudwatch.delete_anomaly_detector
hub.exec.boto3.client.cloudwatch.describe_anomaly_detectors
hub.exec.boto3.client.cloudwatch.put_anomaly_detector
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, namespace: Text, metric_name: Text, stat: Text, dimensions: List = None, configuration: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an anomaly detection model for a CloudWatch metric. You can use the model to display a band of expected
    normal values when the metric is graphed. For more information, see CloudWatch Anomaly Detection.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        namespace(Text): The namespace of the metric to create the anomaly detection model for.
        metric_name(Text): The name of the metric to create the anomaly detection model for.
        dimensions(List, optional): The metric dimensions to create the anomaly detection model for. Defaults to None.
        stat(Text): The statistic to use for the metric and the anomaly detection model.
        configuration(Dict, optional): The configuration specifies details about how the anomaly detection model is to be trained,
            including time ranges to exclude when training and updating the model. You can specify as many
            as 10 time ranges. The configuration can also include the time zone to use for the metric. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudwatch.anomaly_detector.present:
                - name: value
                - namespace: value
                - metric_name: value
                - stat: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudwatch.anomaly_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.cloudwatch.describe_anomaly_detectors(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudwatch.put_anomaly_detector(
                ctx,
                
                
                **{"Namespace": namespace, "MetricName": metric_name, "Dimensions": dimensions, "Stat": stat, "Configuration": configuration}
            )
            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.cloudwatch.describe_anomaly_detectors(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, namespace: Text, metric_name: Text, stat: Text, dimensions: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified anomaly detection model from your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        namespace(Text): The namespace associated with the anomaly detection model to delete.
        metric_name(Text): The metric name associated with the anomaly detection model to delete.
        dimensions(List, optional): The metric dimensions associated with the anomaly detection model to delete. Defaults to None.
        stat(Text): The statistic associated with the anomaly detection model to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cloudwatch.anomaly_detector.absent:
                - name: value
                - namespace: value
                - metric_name: value
                - stat: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudwatch.anomaly_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.cloudwatch.describe_anomaly_detectors(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudwatch.delete_anomaly_detector(
                ctx,
                
                
                **{"Namespace": namespace, "MetricName": metric_name, "Dimensions": dimensions, "Stat": stat}
            )
            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.cloudwatch.describe_anomaly_detectors(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

