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

hub.exec.boto3.client.lookoutmetrics.activate_anomaly_detector
hub.exec.boto3.client.lookoutmetrics.create_anomaly_detector
hub.exec.boto3.client.lookoutmetrics.delete_anomaly_detector
hub.exec.boto3.client.lookoutmetrics.describe_anomaly_detector
hub.exec.boto3.client.lookoutmetrics.list_anomaly_detectors
hub.exec.boto3.client.lookoutmetrics.update_anomaly_detector
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, anomaly_detector_name: Text, anomaly_detector_config: Dict, anomaly_detector_description: Text = None, kms_key_arn: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an anomaly detector.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        anomaly_detector_name(Text): The name of the detector.
        anomaly_detector_description(Text, optional): A description of the detector. Defaults to None.
        anomaly_detector_config(Dict): Contains information about the configuration of the anomaly detector.
        kms_key_arn(Text, optional): The ARN of the KMS key to use to encrypt your data. Defaults to None.
        tags(Dict, optional): A list of tags to apply to the anomaly detector. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lookoutmetrics.anomaly_detector.present:
                - name: value
                - anomaly_detector_name: value
                - anomaly_detector_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lookoutmetrics.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.lookoutmetrics.describe_anomaly_detector(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lookoutmetrics.create_anomaly_detector(
                ctx,
                
                
                **{"AnomalyDetectorName": anomaly_detector_name, "AnomalyDetectorDescription": anomaly_detector_description, "AnomalyDetectorConfig": anomaly_detector_config, "KmsKeyArn": kms_key_arn, "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_anomaly_detector(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, anomaly_detector_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a detector. Deleting an anomaly detector will delete all of its corresponding resources including any
    configured datasets and alerts.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

