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

hub.exec.boto3.client.mq.create_user
hub.exec.boto3.client.mq.delete_user
hub.exec.boto3.client.mq.describe_user
hub.exec.boto3.client.mq.list_users
hub.exec.boto3.client.mq.update_user
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, broker_id: Text, password: Text, username: Text, console_access: bool = None, groups: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an ActiveMQ user.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        broker_id(Text): The unique ID that Amazon MQ generates for the broker.
        console_access(bool, optional): Enables access to the ActiveMQ Web Console for the ActiveMQ user. Defaults to None.
        groups(List, optional): The list of groups (20 maximum) to which the ActiveMQ user belongs. This value can contain only
            alphanumeric characters, dashes, periods, underscores, and tildes (- . _ ~). This value must be
            2-100 characters long. Defaults to None.
        password(Text): Required. The password of the user. This value must be at least 12 characters long, must contain
            at least 4 unique characters, and must not contain commas, colons, or equal signs (,:=).
        username(Text): The username of the ActiveMQ user. This value can contain only alphanumeric characters, dashes,
            periods, underscores, and tildes (- . _ ~). This value must be 2-100 characters long.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mq.create_user(
                ctx,
                
                
                **{"BrokerId": broker_id, "ConsoleAccess": console_access, "Groups": groups, "Password": password, "Username": username}
            )
            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.mq.describe_user(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, broker_id: Text, username: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an ActiveMQ user.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        broker_id(Text): The unique ID that Amazon MQ generates for the broker.
        username(Text): The username of the ActiveMQ user. This value can contain only alphanumeric characters, dashes,
            periods, underscores, and tildes (- . _ ~). This value must be 2-100 characters long.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

