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

hub.exec.boto3.client.opsworks.create_user_profile
hub.exec.boto3.client.opsworks.delete_user_profile
hub.exec.boto3.client.opsworks.describe_user_profiles
hub.exec.boto3.client.opsworks.update_user_profile
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, iam_user_arn: Text, ssh_username: Text = None, ssh_public_key: Text = None, allow_self_management: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new user profile.  Required Permissions: To use this action, an IAM user must have an attached policy
    that explicitly grants permissions. For more information about user permissions, see Managing User Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        iam_user_arn(Text): The user's IAM ARN; this can also be a federated user's ARN.
        ssh_username(Text, optional): The user's SSH user name. The allowable characters are [a-z], [A-Z], [0-9], '-', and '_'. If the
            specified name includes other punctuation marks, AWS OpsWorks Stacks removes them. For example,
            my.name will be changed to myname. If you do not specify an SSH user name, AWS OpsWorks Stacks
            generates one from the IAM user name. Defaults to None.
        ssh_public_key(Text, optional): The user's public SSH key. Defaults to None.
        allow_self_management(bool, optional): Whether users can specify their own SSH public key through the My Settings page. For more
            information, see Setting an IAM User's Public SSH Key. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.opsworks.create_user_profile(
                ctx,
                
                
                **{"IamUserArn": iam_user_arn, "SshUsername": ssh_username, "SshPublicKey": ssh_public_key, "AllowSelfManagement": allow_self_management}
            )
            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.opsworks.describe_user_profiles(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, iam_user_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a user profile.  Required Permissions: To use this action, an IAM user must have an attached policy that
    explicitly grants permissions. For more information about user permissions, see Managing User Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        iam_user_arn(Text): The user's IAM ARN. This can also be a federated user's ARN.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

