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

hub.exec.boto3.client.workspaces.create_workspaces
hub.exec.boto3.client.workspaces.describe_workspaces
hub.exec.boto3.client.workspaces.migrate_workspace
hub.exec.boto3.client.workspaces.reboot_workspaces
hub.exec.boto3.client.workspaces.rebuild_workspaces
hub.exec.boto3.client.workspaces.restore_workspace
hub.exec.boto3.client.workspaces.start_workspaces
hub.exec.boto3.client.workspaces.stop_workspaces
hub.exec.boto3.client.workspaces.terminate_workspaces
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, workspaces: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates one or more WorkSpaces. This operation is asynchronous and returns before the WorkSpaces are created.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        workspaces(List): The WorkSpaces to create. You can specify up to 25 WorkSpaces.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workspaces.create_workspaces(
                ctx,
                
                
                **{"Workspaces": workspaces}
            )
            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.workspaces.describe_workspaces(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, terminate_workspace_requests: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Terminates the specified WorkSpaces.  Terminating a WorkSpace is a permanent action and cannot be undone. The
    user's data is destroyed. If you need to archive any user data, contact AWS Support before terminating the
    WorkSpace.  You can terminate a WorkSpace that is in any state except SUSPENDED. This operation is asynchronous
    and returns before the WorkSpaces have been completely terminated. After a WorkSpace is terminated, the
    TERMINATED state is returned only briefly before the WorkSpace directory metadata is cleaned up, so this state
    is rarely returned. To confirm that a WorkSpace is terminated, check for the WorkSpace ID by using
    DescribeWorkSpaces. If the WorkSpace ID isn't returned, then the WorkSpace has been successfully terminated.
    Simple AD and AD Connector are made available to you free of charge to use with WorkSpaces. If there are no
    WorkSpaces being used with your Simple AD or AD Connector directory for 30 consecutive days, this directory will
    be automatically deregistered for use with Amazon WorkSpaces, and you will be charged for this directory as per
    the AWS Directory Services pricing terms. To delete empty directories, see  Delete the Directory for Your
    WorkSpaces. If you delete your Simple AD or AD Connector directory, you can always create a new one when you
    want to start using WorkSpaces again.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        terminate_workspace_requests(List): The WorkSpaces to terminate. You can specify up to 25 WorkSpaces.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

