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

hub.exec.boto3.client.workspaces.deregister_workspace_directory
hub.exec.boto3.client.workspaces.describe_workspace_directories
hub.exec.boto3.client.workspaces.register_workspace_directory
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_id: Text, enable_work_docs: bool, subnet_ids: List = None, enable_self_service: bool = None, tenancy: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers the specified directory. This operation is asynchronous and returns before the WorkSpace directory is
    registered. If this is the first time you are registering a directory, you will need to create the
    workspaces_DefaultRole role before you can register a directory. For more information, see  Creating the
    workspaces_DefaultRole Role.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_id(Text): The identifier of the directory. You cannot register a directory if it does not have a status of
            Active. If the directory does not have a status of Active, you will receive an
            InvalidResourceStateException error. If you have already registered the maximum number of
            directories that you can register with Amazon WorkSpaces, you will receive a
            ResourceLimitExceededException error. Deregister directories that you are not using for
            WorkSpaces, and try again.
        subnet_ids(List, optional): The identifiers of the subnets for your virtual private cloud (VPC). Make sure that the subnets
            are in supported Availability Zones. The subnets must also be in separate Availability Zones. If
            these conditions are not met, you will receive an OperationNotSupportedException error. Defaults to None.
        enable_work_docs(bool): Indicates whether Amazon WorkDocs is enabled or disabled. If you have enabled this parameter and
            WorkDocs is not available in the Region, you will receive an OperationNotSupportedException
            error. Set EnableWorkDocs to disabled, and try again.
        enable_self_service(bool, optional): Indicates whether self-service capabilities are enabled or disabled. Defaults to None.
        tenancy(Text, optional): Indicates whether your WorkSpace directory is dedicated or shared. To use Bring Your Own License
            (BYOL) images, this value must be set to DEDICATED and your AWS account must be enabled for
            BYOL. If your account has not been enabled for BYOL, you will receive an
            InvalidParameterValuesException error. For more information about BYOL images, see Bring Your
            Own Windows Desktop Images. Defaults to None.
        tags(List, optional): The tags associated with the directory. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workspaces.register_workspace_directory(
                ctx,
                
                
                **{"DirectoryId": directory_id, "SubnetIds": subnet_ids, "EnableWorkDocs": enable_work_docs, "EnableSelfService": enable_self_service, "Tenancy": tenancy, "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.workspaces.describe_workspace_directories(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deregisters the specified directory. This operation is asynchronous and returns before the WorkSpace directory
    is deregistered. If any WorkSpaces are registered to this directory, you must remove them before you can
    deregister the directory.  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.
        directory_id(Text): The identifier of the directory. If any WorkSpaces are registered to this directory, you must
            remove them before you deregister the directory, or you will receive an
            OperationNotSupportedException error.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

