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

hub.exec.boto3.client.connect.create_user
hub.exec.boto3.client.connect.delete_user
hub.exec.boto3.client.connect.describe_user
hub.exec.boto3.client.connect.list_users
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, username: Text, phone_config: Dict, security_profile_ids: List, routing_profile_id: Text, instance_id: Text, password: Text = None, identity_info: Dict = None, directory_user_id: Text = None, hierarchy_group_id: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a user account for the specified Amazon Connect instance. For information about how to create user
    accounts using the Amazon Connect console, see Add Users in the Amazon Connect Administrator Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        username(Text): The user name for the account. For instances not using SAML for identity management, the user
            name can include up to 20 characters. If you are using SAML for identity management, the user
            name can include up to 64 characters from [a-zA-Z0-9_-.\@]+.
        password(Text, optional): The password for the user account. A password is required if you are using Amazon Connect for
            identity management. Otherwise, it is an error to include a password. Defaults to None.
        identity_info(Dict, optional): The information about the identity of the user. Defaults to None.
        phone_config(Dict): The phone settings for the user.
        directory_user_id(Text, optional): The identifier of the user account in the directory used for identity management. If Amazon
            Connect cannot access the directory, you can specify this identifier to authenticate users. If
            you include the identifier, we assume that Amazon Connect cannot access the directory.
            Otherwise, the identity information is used to authenticate users from your directory. This
            parameter is required if you are using an existing directory for identity management in Amazon
            Connect when Amazon Connect cannot access your directory to authenticate users. If you are using
            SAML for identity management and include this parameter, an error is returned. Defaults to None.
        security_profile_ids(List): The identifier of the security profile for the user.
        routing_profile_id(Text): The identifier of the routing profile for the user.
        hierarchy_group_id(Text, optional): The identifier of the hierarchy group for the user. Defaults to None.
        instance_id(Text): The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the
            instance.
        tags(Dict, optional): One or more tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.connect.user.present:
                - name: value
                - username: value
                - phone_config: value
                - security_profile_ids: value
                - routing_profile_id: value
                - instance_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.connect.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.connect.describe_user(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.connect.create_user(
                ctx,
                
                
                **{"Username": username, "Password": password, "IdentityInfo": identity_info, "PhoneConfig": phone_config, "DirectoryUserId": directory_user_id, "SecurityProfileIds": security_profile_ids, "RoutingProfileId": routing_profile_id, "HierarchyGroupId": hierarchy_group_id, "InstanceId": instance_id, "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.connect.describe_user(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_id: Text, user_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a user account from the specified Amazon Connect instance. For information about what happens to a
    user's data when their account is deleted, see Delete Users from Your Amazon Connect Instance in the Amazon
    Connect Administrator Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_id(Text): The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the
            instance.
        user_id(Text): The identifier of the user.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

