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

hub.exec.boto3.client.opsworks.deregister_rds_db_instance
hub.exec.boto3.client.opsworks.describe_rds_db_instances
hub.exec.boto3.client.opsworks.register_rds_db_instance
hub.exec.boto3.client.opsworks.update_rds_db_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, stack_id: Text, rds_db_instance_arn: Text, db_user: Text, db_password: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers an Amazon RDS instance with a stack.  Required Permissions: To use this action, an IAM user must have
    a Manage permissions level for the stack, or an attached policy that explicitly grants permissions. For more
    information on user permissions, see Managing User Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        stack_id(Text): The stack ID.
        rds_db_instance_arn(Text): The Amazon RDS instance's ARN.
        db_user(Text): The database's master user name.
        db_password(Text): The database password.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.opsworks.rds_db_instance.present:
                - name: value
                - stack_id: value
                - rds_db_instance_arn: value
                - db_user: value
                - db_password: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.opsworks.rds_db_instance.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_rds_db_instances(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.opsworks.register_rds_db_instance(
                ctx,
                
                
                **{"StackId": stack_id, "RdsDbInstanceArn": rds_db_instance_arn, "DbUser": db_user, "DbPassword": db_password}
            )
            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_rds_db_instances(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rds_db_instance_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deregisters an Amazon RDS instance.  Required Permissions: To use this action, an IAM user must have a Manage
    permissions level for the stack, or an attached policy that explicitly grants permissions. For more information
    on user permissions, see Managing User Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rds_db_instance_arn(Text): The Amazon RDS instance's ARN.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

