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

hub.exec.boto3.client.mturk.create_worker_block
hub.exec.boto3.client.mturk.delete_worker_block
hub.exec.boto3.client.mturk.list_worker_blocks
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, worker_id: Text, reason: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    The CreateWorkerBlock operation allows you to prevent a Worker from working on your HITs. For example, you can
    block a Worker who is producing poor quality work. You can block up to 100,000 Workers.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        worker_id(Text): The ID of the Worker to block.
        reason(Text): A message explaining the reason for blocking the Worker. This parameter enables you to keep
            track of your Workers. The Worker does not see this message.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mturk.worker_block.present:
                - name: value
                - worker_id: value
                - reason: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mturk.worker_block.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.mturk.list_worker_blocks(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mturk.create_worker_block(
                ctx,
                
                
                **{"WorkerId": worker_id, "Reason": reason}
            )
            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.mturk.list_worker_blocks(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, worker_id: Text, reason: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    The DeleteWorkerBlock operation allows you to reinstate a blocked Worker to work on your HITs. This operation
    reverses the effects of the CreateWorkerBlock operation. You need the Worker ID to use this operation. If the
    Worker ID is missing or invalid, this operation fails and returns the message “WorkerId is invalid.” If the
    specified Worker is not blocked, this operation returns successfully.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        worker_id(Text): The ID of the Worker to unblock.
        reason(Text, optional): A message that explains the reason for unblocking the Worker. The Worker does not see this
            message. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.mturk.delete_worker_block(
                ctx,
                
                
                **{"WorkerId": worker_id, "Reason": reason}
            )
            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.mturk.list_worker_blocks(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

