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

hub.exec.boto3.client.iot.create_custom_metric
hub.exec.boto3.client.iot.delete_custom_metric
hub.exec.boto3.client.iot.describe_custom_metric
hub.exec.boto3.client.iot.list_custom_metrics
hub.exec.boto3.client.iot.update_custom_metric
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, metric_name: Text, metric_type: Text, client_request_token: Text, display_name: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Use this API to define a Custom Metric published by your devices to Device Defender.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        metric_name(Text):  The name of the custom metric. This will be used in the metric report submitted from the
            device/thing. Shouldn't begin with aws:. Cannot be updated once defined.
        display_name(Text, optional):  Field represents a friendly name in the console for the custom metric; it doesn't have to be
            unique. Don't use this name as the metric identifier in the device metric report. Can be updated
            once defined. Defaults to None.
        metric_type(Text):  The type of the custom metric. Types include string-list, ip-address-list, number-list, and
            number.
        tags(List, optional):  Metadata that can be used to manage the custom metric. Defaults to None.
        client_request_token(Text): Each custom metric must have a unique client request token. If you try to create a new custom
            metric that already exists with a different token, an exception occurs. If you omit this value,
            AWS SDKs will automatically generate a unique client request.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.custom_metric.present:
                - name: value
                - metric_name: value
                - metric_type: value
                - client_request_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.custom_metric.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.iot.describe_custom_metric(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_custom_metric(
                ctx,
                
                
                **{"metricName": metric_name, "displayName": display_name, "metricType": metric_type, "tags": tags, "clientRequestToken": client_request_token}
            )
            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.iot.describe_custom_metric(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, metric_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Before you can delete a custom metric, you must first remove the custom metric from all security profiles it's
    a part of. The security profile associated with the custom metric can be found using the ListSecurityProfiles
    API with metricName set to your custom metric name.   Deletes a Device Defender detect custom metric.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        metric_name(Text):  The name of the custom metric.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

