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

hub.exec.boto3.client.workdocs.activate_user
hub.exec.boto3.client.workdocs.create_user
hub.exec.boto3.client.workdocs.deactivate_user
hub.exec.boto3.client.workdocs.delete_user
hub.exec.boto3.client.workdocs.describe_users
hub.exec.boto3.client.workdocs.update_user
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, username: Text, given_name: Text, surname: Text, password: Text, organization_id: Text = None, email_address: Text = None, time_zone_id: Text = None, storage_rule: Dict = None, authentication_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a user in a Simple AD or Microsoft AD directory. The status of a newly created user is "ACTIVE". New
    users can access Amazon WorkDocs.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        organization_id(Text, optional): The ID of the organization. Defaults to None.
        username(Text): The login name of the user.
        email_address(Text, optional): The email address of the user. Defaults to None.
        given_name(Text): The given name of the user.
        surname(Text): The surname of the user.
        password(Text): The password of the user.
        time_zone_id(Text, optional): The time zone ID of the user. Defaults to None.
        storage_rule(Dict, optional): The amount of storage for the user. Defaults to None.
        authentication_token(Text, optional): Amazon WorkDocs authentication token. Not required when using AWS administrator credentials to
            access the API. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.workdocs.user.present:
                - name: value
                - username: value
                - given_name: value
                - surname: value
                - password: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.workdocs.user.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.workdocs.describe_users(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workdocs.create_user(
                ctx,
                
                
                **{"OrganizationId": organization_id, "Username": username, "EmailAddress": email_address, "GivenName": given_name, "Surname": surname, "Password": password, "TimeZoneId": time_zone_id, "StorageRule": storage_rule, "AuthenticationToken": authentication_token}
            )
            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.workdocs.describe_users(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_id: Text, authentication_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified user from a Simple AD or Microsoft AD directory.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        authentication_token(Text, optional): Amazon WorkDocs authentication token. Do not set this field when using administrative API
            actions, as in accessing the API using AWS credentials. Defaults to None.
        user_id(Text): The ID of the user.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.workdocs.delete_user(
                ctx,
                
                
                **{"AuthenticationToken": authentication_token, "UserId": user_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.workdocs.describe_users(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

