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

hub.exec.boto3.client.logs.delete_metric_filter
hub.exec.boto3.client.logs.describe_metric_filters
hub.exec.boto3.client.logs.put_metric_filter
hub.exec.boto3.client.logs.test_metric_filter
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, log_group_name: Text, filter_name: Text, filter_pattern: Text, metric_transformations: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a metric filter and associates it with the specified log group. Metric filters allow you to
    configure rules to extract metric data from log events ingested through PutLogEvents. The maximum number of
    metric filters that can be associated with a log group is 100. When you create a metric filter, you can also
    optionally assign a unit and dimensions to the metric that is created.  Metrics extracted from log events are
    charged as custom metrics. To prevent unexpected high charges, do not specify high-cardinality fields such as
    IPAddress or requestID as dimensions. Each different value found for a dimension is treated as a separate metric
    and accrues charges as a separate custom metric.  To help prevent accidental high charges, Amazon disables a
    metric filter if it generates 1000 different name/value pairs for the dimensions that you have specified within
    a certain amount of time. You can also set up a billing alarm to alert you if your charges are higher than
    expected. For more information, see  Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services
    Charges.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        log_group_name(Text): The name of the log group.
        filter_name(Text): A name for the metric filter.
        filter_pattern(Text): A filter pattern for extracting metric data out of ingested log events.
        metric_transformations(List): A collection of information that defines how metric data gets emitted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.logs.metric_filter.present:
                - name: value
                - log_group_name: value
                - filter_name: value
                - filter_pattern: value
                - metric_transformations: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.logs.metric_filter.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.logs.describe_metric_filters(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.put_metric_filter(
                ctx,
                
                
                **{"logGroupName": log_group_name, "filterName": filter_name, "filterPattern": filter_pattern, "metricTransformations": metric_transformations}
            )
            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.logs.describe_metric_filters(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, log_group_name: Text, filter_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified metric filter.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        log_group_name(Text): The name of the log group.
        filter_name(Text): The name of the metric filter.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.logs.metric_filter.absent:
                - name: value
                - log_group_name: value
                - filter_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.logs.metric_filter.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.logs.describe_metric_filters(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.delete_metric_filter(
                ctx,
                
                
                **{"logGroupName": log_group_name, "filterName": filter_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.logs.describe_metric_filters(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

