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

hub.exec.boto3.client.appstream.create_user
hub.exec.boto3.client.appstream.delete_user
hub.exec.boto3.client.appstream.describe_users
hub.exec.boto3.client.appstream.disable_user
hub.exec.boto3.client.appstream.enable_user
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_name: Text, authentication_type: Text, message_action: Text = None, first_name: Text = None, last_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new user in the user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The email address of the user.  Users' email addresses are case-sensitive. During login, if they
            specify an email address that doesn't use the same capitalization as the email address specified
            when their user pool account was created, a "user does not exist" error message displays.
        message_action(Text, optional): The action to take for the welcome email that is sent to a user after the user is created in the
            user pool. If you specify SUPPRESS, no email is sent. If you specify RESEND, do not specify the
            first name or last name of the user. If the value is null, the email is sent.   The temporary
            password in the welcome email is valid for only 7 days. If users don’t set their passwords
            within 7 days, you must send them a new welcome email. Defaults to None.
        first_name(Text, optional): The first name, or given name, of the user. Defaults to None.
        last_name(Text, optional): The last name, or surname, of the user. Defaults to None.
        authentication_type(Text): The authentication type for the user. You must specify USERPOOL.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appstream.create_user(
                ctx,
                
                
                **{"UserName": user_name, "MessageAction": message_action, "FirstName": first_name, "LastName": last_name, "AuthenticationType": authentication_type}
            )
            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.appstream.describe_users(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_name: Text, authentication_type: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a user from the user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The email address of the user.  Users' email addresses are case-sensitive.
        authentication_type(Text): The authentication type for the user. You must specify USERPOOL.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

