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

hub.exec.boto3.client.logs.delete_subscription_filter
hub.exec.boto3.client.logs.describe_subscription_filters
hub.exec.boto3.client.logs.put_subscription_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, destination_arn: Text, role_arn: Text = None, distribution: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a subscription filter and associates it with the specified log group. Subscription filters
    allow you to subscribe to a real-time stream of log events ingested through PutLogEvents and have them delivered
    to a specific destination. When log events are sent to the receiving service, they are Base64 encoded and
    compressed with the gzip format. The following destinations are supported for subscription filters:   An Amazon
    Kinesis stream belonging to the same account as the subscription filter, for same-account delivery.   A logical
    destination that belongs to a different account, for cross-account delivery.   An Amazon Kinesis Firehose
    delivery stream that belongs to the same account as the subscription filter, for same-account delivery.   An
    Lambda function that belongs to the same account as the subscription filter, for same-account delivery.   Each
    log group can have up to two subscription filters associated with it. If you are updating an existing filter,
    you must specify the correct name in filterName.  To perform a PutSubscriptionFilter operation, you must also
    have the iam:PassRole permission.

    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 subscription filter. If you are updating an existing filter, you must specify the
            correct name in filterName. To find the name of the filter currently associated with a log
            group, use DescribeSubscriptionFilters.
        filter_pattern(Text): A filter pattern for subscribing to a filtered stream of log events.
        destination_arn(Text): The ARN of the destination to deliver matching log events to. Currently, the supported
            destinations are:   An Amazon Kinesis stream belonging to the same account as the subscription
            filter, for same-account delivery.   A logical destination (specified using an ARN) belonging to
            a different account, for cross-account delivery. If you are setting up a cross-account
            subscription, the destination must have an IAM policy associated with it that allows the sender
            to send logs to the destination. For more information, see PutDestinationPolicy.   An Amazon
            Kinesis Firehose delivery stream belonging to the same account as the subscription filter, for
            same-account delivery.   A Lambda function belonging to the same account as the subscription
            filter, for same-account delivery.
        role_arn(Text, optional): The ARN of an IAM role that grants CloudWatch Logs permissions to deliver ingested log events to
            the destination stream. You don't need to provide the ARN when you are working with a logical
            destination for cross-account delivery. Defaults to None.
        distribution(Text, optional): The method used to distribute log data to the destination. By default, log data is grouped by
            log stream, but the grouping can be set to random for a more even distribution. This property is
            only applicable when the destination is an Amazon Kinesis stream. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.put_subscription_filter(
                ctx,
                
                
                **{"logGroupName": log_group_name, "filterName": filter_name, "filterPattern": filter_pattern, "destinationArn": destination_arn, "roleArn": role_arn, "distribution": distribution}
            )
            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_subscription_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 subscription 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 subscription filter.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.logs.subscription_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.subscription_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_subscription_filters(name)

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

