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

hub.exec.boto3.client.timestream_write.create_database
hub.exec.boto3.client.timestream_write.delete_database
hub.exec.boto3.client.timestream_write.describe_database
hub.exec.boto3.client.timestream_write.list_databases
hub.exec.boto3.client.timestream_write.update_database
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, database_name: Text, kms_key_id: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Timestream database. If the KMS key is not specified, the database will be encrypted with a
    Timestream managed KMS key located in your account. Refer to AWS managed KMS keys for more info. Service quotas
    apply. For more information, see Access Management in the Timestream Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        database_name(Text): The name of the Timestream database.
        kms_key_id(Text, optional): The KMS key for the database. If the KMS key is not specified, the database will be encrypted
            with a Timestream managed KMS key located in your account. Refer to AWS managed KMS keys for
            more info. Defaults to None.
        tags(List, optional):  A list of key-value pairs to label the table. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.timestream_write.create_database(
                ctx,
                
                
                **{"DatabaseName": database_name, "KmsKeyId": kms_key_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.timestream_write.describe_database(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, database_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a given Timestream database. This is an irreversible operation. After a database is deleted, the time
    series data from its tables cannot be recovered.  All tables in the database must be deleted first, or a
    ValidationException error will be thrown.  Due to the nature of distributed retries, the operation can return
    either success or a ResourceNotFoundException. Clients should consider them equivalent.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        database_name(Text): The name of the Timestream database to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

