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

hub.exec.boto3.client.backup.create_backup_vault
hub.exec.boto3.client.backup.delete_backup_vault
hub.exec.boto3.client.backup.describe_backup_vault
hub.exec.boto3.client.backup.list_backup_vaults
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, backup_vault_name: Text, backup_vault_tags: Dict = None, encryption_key_arn: Text = None, creator_request_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a logical container where backups are stored. A CreateBackupVault request includes a name, optionally
    one or more resource tags, an encryption key, and a request ID.  Sensitive data, such as passport numbers,
    should not be included the name of a backup vault.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_vault_name(Text): The name of a logical container where backups are stored. Backup vaults are identified by names
            that are unique to the account used to create them and the AWS Region where they are created.
            They consist of letters, numbers, and hyphens.
        backup_vault_tags(Dict, optional): Metadata that you can assign to help organize the resources that you create. Each tag is a key-
            value pair. Defaults to None.
        encryption_key_arn(Text, optional): The server-side encryption key that is used to protect your backups; for example,
            arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab. Defaults to None.
        creator_request_id(Text, optional): A unique string that identifies the request and allows failed requests to be retried without the
            risk of running the operation twice. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.backup.create_backup_vault(
                ctx,
                
                
                **{"BackupVaultName": backup_vault_name, "BackupVaultTags": backup_vault_tags, "EncryptionKeyArn": encryption_key_arn, "CreatorRequestId": creator_request_id}
            )
            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.backup.describe_backup_vault(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, backup_vault_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the backup vault identified by its name. A vault can be deleted only if it is empty.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_vault_name(Text): The name of a logical container where backups are stored. Backup vaults are identified by names
            that are unique to the account used to create them and the AWS Region where they are created.
            They consist of lowercase letters, numbers, and hyphens.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

