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

hub.exec.boto3.client.cloudwatch.delete_metric_stream
hub.exec.boto3.client.cloudwatch.get_metric_stream
hub.exec.boto3.client.cloudwatch.list_metric_streams
hub.exec.boto3.client.cloudwatch.put_metric_stream
hub.exec.boto3.client.cloudwatch.start_metric_streams
hub.exec.boto3.client.cloudwatch.stop_metric_streams
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, firehose_arn: Text, role_arn: Text, output_format: Text, include_filters: List = None, exclude_filters: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a metric stream. Metric streams can automatically stream CloudWatch metrics to Amazon Web
    Services destinations including Amazon S3 and to many third-party solutions. For more information, see  Using
    Metric Streams. To create a metric stream, you must be logged on to an account that has the iam:PassRole
    permission and either the CloudWatchFullAccess policy or the cloudwatch:PutMetricStream permission. When you
    create or update a metric stream, you choose one of the following:   Stream metrics from all metric namespaces
    in the account.   Stream metrics from all metric namespaces in the account, except for the namespaces that you
    list in ExcludeFilters.   Stream metrics from only the metric namespaces that you list in IncludeFilters.   When
    you use PutMetricStream to create a new metric stream, the stream is created in the running state. If you use it
    to update an existing stream, the state of the stream is not changed.

    Args:
        name(Text): If you are creating a new metric stream, this is the name for the new stream. The name must be
            different than the names of other metric streams in this account and Region. If you are updating
            a metric stream, specify the name of that stream here. Valid characters are A-Z, a-z, 0-9, "-"
            and "_".
        include_filters(List, optional): If you specify this parameter, the stream sends only the metrics from the metric namespaces that
            you specify here. You cannot include IncludeFilters and ExcludeFilters in the same operation. Defaults to None.
        exclude_filters(List, optional): If you specify this parameter, the stream sends metrics from all metric namespaces except for
            the namespaces that you specify here. You cannot include ExcludeFilters and IncludeFilters in
            the same operation. Defaults to None.
        firehose_arn(Text): The ARN of the Amazon Kinesis Firehose delivery stream to use for this metric stream. This
            Amazon Kinesis Firehose delivery stream must already exist and must be in the same account as
            the metric stream.
        role_arn(Text): The ARN of an IAM role that this metric stream will use to access Amazon Kinesis Firehose
            resources. This IAM role must already exist and must be in the same account as the metric
            stream. This IAM role must include the following permissions:   firehose:PutRecord
            firehose:PutRecordBatch.
        output_format(Text): The output format for the stream. Valid values are json and opentelemetry0.7. For more
            information about metric stream output formats, see  Metric streams output formats.
        tags(List, optional): A list of key-value pairs to associate with the metric stream. You can associate as many as 50
            tags with a metric stream. Tags can help you organize and categorize your resources. You can
            also use them to scope user permissions by granting a user permission to access or change only
            resources with certain tag values. You can use this parameter only when you are creating a new
            metric stream. If you are using this operation to update an existing metric stream, any tags you
            specify in this parameter are ignored. To change the tags of an existing metric stream, use
            TagResource or UntagResource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudwatch.metric_stream.present:
                - name: value
                - firehose_arn: value
                - role_arn: value
                - output_format: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudwatch.metric_stream.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.get_metric_stream(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudwatch.put_metric_stream(
                ctx,
                
                
                **{"Name": name, "IncludeFilters": include_filters, "ExcludeFilters": exclude_filters, "FirehoseArn": firehose_arn, "RoleArn": role_arn, "OutputFormat": output_format, "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.cloudwatch.get_metric_stream(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Permanently deletes the metric stream that you specify.

    Args:
        name(Text): The name of the metric stream to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

