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

hub.exec.boto3.client.iam.create_login_profile
hub.exec.boto3.client.iam.delete_login_profile
hub.exec.boto3.client.iam.get_login_profile
hub.exec.boto3.client.iam.update_login_profile
resource = hub.tool.boto3.resource.create(ctx, "iam", "LoginProfile", name)
hub.tool.boto3.resource.exec(resource, create, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, update, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_name: Text, password: Text, password_reset_required: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a password for the specified IAM user. A password allows an IAM user to access Amazon Web Services
    services through the Management Console. You can use the CLI, the Amazon Web Services API, or the Users page in
    the IAM console to create a password for any IAM user. Use ChangePassword to update your own existing password
    in the My Security Credentials page in the Management Console. For more information about managing passwords,
    see Managing passwords in the IAM User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The name of the IAM user to create a password for. The user must already exist. This parameter
            allows (through its regex pattern) a string of characters consisting of upper and lowercase
            alphanumeric characters with no spaces. You can also include any of the following characters:
            _+=,.@-.
        password(Text): The new password for the user. The regex pattern that is used to validate this parameter is a
            string of characters. That string can include almost any printable ASCII character from the
            space (\u0020) through the end of the ASCII character range (\u00FF). You can also include the
            tab (\u0009), line feed (\u000A), and carriage return (\u000D) characters. Any of these
            characters are valid in a password. However, many tools, such as the Management Console, might
            restrict the ability to type certain characters because they have special meaning within that
            tool.
        password_reset_required(bool, optional): Specifies whether the user is required to set a new password on next sign-in. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iam.login_profile.present:
                - name: value
                - user_name: value
                - password: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.login_profile.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "LoginProfile", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.create_login_profile(
                ctx,
                
                
                **{"UserName": user_name, "Password": password, "PasswordResetRequired": password_reset_required}
            )
            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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the password for the specified IAM user, which terminates the user's ability to access Amazon Web
    Services services through the Management Console. You can use the CLI, the Amazon Web Services API, or the Users
    page in the IAM console to delete a password for any IAM user. You can use ChangePassword to update, but not
    delete, your own password in the My Security Credentials page in the Management Console.   Deleting a user's
    password does not prevent a user from accessing Amazon Web Services through the command line interface or the
    API. To prevent all user access, you must also either make any access keys inactive or delete them. For more
    information about making keys inactive or deleting them, see UpdateAccessKey and DeleteAccessKey.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The name of the user whose password you want to delete. This parameter allows (through its regex
            pattern) a string of characters consisting of upper and lowercase alphanumeric characters with
            no spaces. You can also include any of the following characters: _+=,.@-.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iam.login_profile.absent:
                - name: value
                - user_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.login_profile.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "LoginProfile", name)

    before = await hub.tool.boto3.resource.describe(resource)

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

