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

hub.exec.boto3.client.fsx.cancel_data_repository_task
hub.exec.boto3.client.fsx.create_data_repository_task
hub.exec.boto3.client.fsx.describe_data_repository_tasks
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, type_: Text, file_system_id: Text, report: Dict, paths: List = None, client_request_token: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon FSx for Lustre data repository task. You use data repository tasks to perform bulk operations
    between your Amazon FSx file system and its linked data repository. An example of a data repository task is
    exporting any data and metadata changes, including POSIX metadata, to files, directories, and symbolic links
    (symlinks) from your FSx file system to its linked data repository. A CreateDataRepositoryTask operation will
    fail if a data repository is not linked to the FSx file system. To learn more about data repository tasks, see
    Data Repository Tasks. To learn more about linking a data repository to your file system, see Linking your file
    system to an S3 bucket.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        type_(Text): Specifies the type of data repository task to create.
        paths(List, optional): (Optional) The path or paths on the Amazon FSx file system to use when the data repository task
            is processed. The default path is the file system root directory. The paths you provide need to
            be relative to the mount point of the file system. If the mount point is /mnt/fsx and
            /mnt/fsx/path1 is a directory or file on the file system you want to export, then the path to
            provide is path1. If a path that you provide isn't valid, the task fails. Defaults to None.
        file_system_id(Text): The globally unique ID of the file system, assigned by Amazon FSx.
        report(Dict): Defines whether or not Amazon FSx provides a CompletionReport once the task has completed. A
            CompletionReport provides a detailed report on the files that Amazon FSx processed that meet the
            criteria specified by the Scope parameter. For more information, see Working with Task
            Completion Reports.
        client_request_token(Text, optional): (Optional) An idempotency token for resource creation, in a string of up to 64 ASCII characters.
            This token is automatically filled on your behalf when you use the AWS Command Line Interface
            (AWS CLI) or an AWS SDK. Defaults to None.
        tags(List, optional): A list of Tag values, with a maximum of 50 elements. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.fsx.data_repository_task.present:
                - name: value
                - type_: value
                - file_system_id: value
                - report: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.fsx.data_repository_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.fsx.describe_data_repository_tasks(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.fsx.create_data_repository_task(
                ctx,
                
                
                **{"Type": type_, "Paths": paths, "FileSystemId": file_system_id, "Report": report, "ClientRequestToken": client_request_token, "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.fsx.describe_data_repository_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 an existing Amazon FSx for Lustre data repository task if that task is in either the PENDING or
    EXECUTING state. When you cancel a task, Amazon FSx does the following.   Any files that FSx has already
    exported are not reverted.   FSx continues to export any files that are "in-flight" when the cancel operation is
    received.   FSx does not export any files that have not yet been exported.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        task_id(Text): Specifies the data repository task to cancel.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

