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

hub.exec.boto3.client.snow_device_management.cancel_task
hub.exec.boto3.client.snow_device_management.create_task
hub.exec.boto3.client.snow_device_management.describe_task
hub.exec.boto3.client.snow_device_management.list_tasks
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, command: Dict, targets: List, client_token: Text = None, description: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Instructs one or more devices to start a task, such as unlocking or rebooting.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): A token ensuring that the action is called only once with the specified details. Defaults to None.
        command(Dict): The task to be performed. Only one task is executed on a device at a time.
        description(Text, optional): A description of the task and its targets. Defaults to None.
        tags(Dict, optional): Optional metadata that you assign to a resource. You can use tags to categorize a resource in
            different ways, such as by purpose, owner, or environment. Defaults to None.
        targets(List): A list of managed device IDs.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.snow_device_management.create_task(
                ctx,
                
                
                **{"clientToken": client_token, "command": command, "description": description, "tags": tags, "targets": targets}
            )
            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.snow_device_management.describe_task(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**
    
    Sends a cancel request for a specified task. You can cancel a task only if it's still in a QUEUED state. Tasks
    that are already running can't be cancelled.  A task might still run if it's processed from the queue before the
    CancelTask operation changes the task's state.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        task_id(Text): The ID of the task that you are attempting to cancel. You can retrieve a task ID by using the
            ListTasks operation.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

