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

hub.exec.boto3.client.datasync.create_task
hub.exec.boto3.client.datasync.delete_task
hub.exec.boto3.client.datasync.describe_task
hub.exec.boto3.client.datasync.list_tasks
hub.exec.boto3.client.datasync.update_task
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, source_location_arn: Text, destination_location_arn: Text, name: Text = None, cloud_watch_log_group_arn: Text = None, options: Dict = None, excludes: List = None, schedule: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a task. A task includes a source location and a destination location, and a configuration that specifies
    how data is transferred. A task always transfers data from the source location to the destination location. The
    configuration specifies options such as task scheduling, bandwidth limits, etc. A task is the complete
    definition of a data transfer. When you create a task that transfers data between AWS services in different AWS
    Regions, one of the two locations that you specify must reside in the Region where DataSync is being used. The
    other location must be specified in a different Region. You can transfer data between commercial AWS Regions
    except for China, or between AWS GovCloud (US-East and US-West) Regions.  When you use DataSync to copy files or
    objects between AWS Regions, you pay for data transfer between Regions. This is billed as data transfer OUT from
    your source Region to your destination Region. For more information, see Data Transfer pricing.

    Args:
        name(Text, optional): The name of a task. This value is a text reference that is used to identify the task in the
            console. Defaults to None.
        source_location_arn(Text): The Amazon Resource Name (ARN) of the source location for the task.
        destination_location_arn(Text): The Amazon Resource Name (ARN) of an AWS storage resource's location.
        cloud_watch_log_group_arn(Text, optional): The Amazon Resource Name (ARN) of the Amazon CloudWatch log group that is used to monitor and
            log events in the task. Defaults to None.
        options(Dict, optional): The set of configuration options that control the behavior of a single execution of the task
            that occurs when you call StartTaskExecution. You can configure these options to preserve
            metadata such as user ID (UID) and group ID (GID), file permissions, data integrity
            verification, and so on. For each individual task execution, you can override these options by
            specifying the OverrideOptions before starting the task execution. For more information, see the
            StartTaskExecution operation. Defaults to None.
        excludes(List, optional): A list of filter rules that determines which files to exclude from a task. The list should
            contain a single filter string that consists of the patterns to exclude. The patterns are
            delimited by "|" (that is, a pipe), for example, "/folder1|/folder2". Defaults to None.
        schedule(Dict, optional): Specifies a schedule used to periodically transfer files from a source to a destination
            location. The schedule should be specified in UTC time. For more information, see Scheduling
            your task. Defaults to None.
        tags(List, optional): The key-value pair that represents the tag that you want to add to the resource. The value can
            be an empty string. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.datasync.task.present:
                - source_location_arn: value
                - destination_location_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.datasync.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.datasync.describe_task(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.datasync.create_task(
                ctx,
                
                
                **{"Name": name, "SourceLocationArn": source_location_arn, "DestinationLocationArn": destination_location_arn, "CloudWatchLogGroupArn": cloud_watch_log_group_arn, "Options": options, "Excludes": excludes, "Schedule": schedule, "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.datasync.describe_task(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, task_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a task.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        task_arn(Text): The Amazon Resource Name (ARN) of the task to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

