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

hub.exec.boto3.client.logs.cancel_export_task
hub.exec.boto3.client.logs.create_export_task
hub.exec.boto3.client.logs.describe_export_tasks
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, log_group_name: Text, from_: int, to: int, destination: Text, task_name: Text = None, log_stream_name_prefix: Text = None, destination_prefix: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an export task, which allows you to efficiently export data from a log group to an Amazon S3 bucket.
    When you perform a CreateExportTask operation, you must use credentials that have permission to write to the S3
    bucket that you specify as the destination. This is an asynchronous call. If all the required information is
    provided, this operation initiates an export task and responds with the ID of the task. After the task has
    started, you can use DescribeExportTasks to get the status of the export task. Each account can only have one
    active (RUNNING or PENDING) export task at a time. To cancel an export task, use CancelExportTask. You can
    export logs from multiple log groups or multiple time ranges to the same S3 bucket. To separate out log data for
    each export task, you can specify a prefix to be used as the Amazon S3 key prefix for all exported objects.
    Exporting to S3 buckets that are encrypted with AES-256 is supported. Exporting to S3 buckets encrypted with
    SSE-KMS is not supported.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        task_name(Text, optional): The name of the export task. Defaults to None.
        log_group_name(Text): The name of the log group.
        log_stream_name_prefix(Text, optional): Export only log streams that match the provided prefix. If you don't specify a value, no prefix
            filter is applied. Defaults to None.
        from_(int): The start time of the range for the request, expressed as the number of milliseconds after Jan
            1, 1970 00:00:00 UTC. Events with a timestamp earlier than this time are not exported.
        to(int): The end time of the range for the request, expreswatchlogsdocused as the number of milliseconds
            after Jan 1, 1970 00:00:00 UTC. Events with a timestamp later than this time are not exported.
        destination(Text): The name of S3 bucket for the exported log data. The bucket must be in the same Amazon Web
            Services region.
        destination_prefix(Text, optional): The prefix used as the start of the key for every object exported. If you don't specify a value,
            the default is exportedlogs. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.logs.export_task.present:
                - name: value
                - log_group_name: value
                - from_: value
                - to: value
                - destination: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.logs.export_task.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_export_tasks(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.create_export_task(
                ctx,
                
                
                **{"taskName": task_name, "logGroupName": log_group_name, "logStreamNamePrefix": log_stream_name_prefix, "from": from_, "to": to, "destination": destination, "destinationPrefix": destination_prefix}
            )
            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_export_tasks(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, task_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Cancels the specified export task. The task must be in the PENDING or RUNNING state.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        task_id(Text): The ID of the export task.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

